DEV Community

Cover image for If-Else Statement in Dart
Jay Tillu😎
Jay Tillu😎

Posted on • Updated on

If-Else Statement in Dart

If-else is a conditional statement. It used when we want to check the condition. but apart from if statement, here we have else block too. Which will execute if the condition of if a statement is evaluated false?


if (boolean_expression) {
  //Statements to be executed if the condition is true
} else {
  //Statements to be executed if the condition is false
Enter fullscreen mode Exit fullscreen mode
  • If the Boolean expression evaluates to be true, then the block of code inside the if statement will be executed.

  • If the Boolean expression evaluates to be false, then the else’s code block will be executed.

  • Here remember that else is optional here.

Sample Code

void main() {
  int number = 35;
  if (number > 5) {
    print("Number is greater than 5");
  } else {
    print("Number is less than 5");

Number is greater than 5
Enter fullscreen mode Exit fullscreen mode

So now I think you get the basic idea about if-else in the dart. If-else is not much more different then other languages. If you have previous programming experience then maybe you’ll feel right at home at this moment.

Share your thoughts on the dart and if I miss something, please let me know. I’ll happy to learn it from you. Till then Keep Loving, Keep Coding. I’ll surely catch you up in another article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

For More Information Please Visit Following Links

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

Top comments (0)