{"id":3592,"date":"2022-05-20T11:08:15","date_gmt":"2022-05-20T11:08:15","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=3592"},"modified":"2022-05-20T11:08:15","modified_gmt":"2022-05-20T11:08:15","slug":"dart-if-else-statement","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/05\/20\/dart-if-else-statement\/","title":{"rendered":"Dart if-else Statement"},"content":{"rendered":"\n<p>In Dart, if-block is executed when the given condition is true. If the given condition is false, else-block is executed. The else block is associated with the if-block.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dart if\u2026else Statement Flow Diagram<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/tutorial\/dart\/images\/dart-if-else-statement.png\" alt=\"Dart if-else Statement\"\/><\/figure>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(condition) {  \n      \/\/ statement(s);  \n} else {  \n    \/\/ statement(s);  \n} <\/code><\/pre>\n\n\n\n<p>Here, if -else statement is used for either types of result TRUE or False. If the given condition evaluates true, then if body is executed and if the given condition evaluates false; then, the else body is executed.<\/p>\n\n\n\n<p>Let&#8217;s understand the following example.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {  \n     var x = 20;  \n     var y = 30;  \n    print(\"if-else statement example\");  \n  \n    if(x > y){  \n         print(\"x is greater than y\");     \n} else {  \n         print(\"y is greater than x\");  \n  \n};  \n  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if-else statement example\ny is greater than x\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above code, we have two variables which stored integer value. The given condition evaluated false then it printed the else-block.<\/p>\n\n\n\n<p><strong>Example -2 Write a program to find the given number is even or odd.<\/strong><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-if-else-statement#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void main() {  \n     var num = 20;  \n       \n    print(\"if-else statement example\");  \n  \n    if(num%2 == 0){  \n         print(\"The given number is even\");     \n} else {  \n         print(\"The given number is odd\");  \n};  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>If-else statement example\nThe given number is even\n<\/code><\/pre>\n\n\n\n<p><strong>Explanation &#8211;<\/strong><\/p>\n\n\n\n<p>In the above example, we have an integer variable&nbsp;<strong>num<\/strong>&nbsp;which stored 20 and we used the if-else statement to check whether a given number is even of odd. The given condition evaluated true because modulus of 20 is equal to 0 then it printed the given number is even on the screen.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Dart, if-block is executed when the given condition is true. If the given condition is false, else-block is executed. The else block is associated with the if-block. Dart if\u2026else Statement Flow Diagram Syntax: Here, if -else statement is used for either types of result TRUE or False. If the given condition evaluates true, then [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[916],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3592"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=3592"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/3592\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=3592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=3592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=3592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}