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?
Syntax
if (boolean_expression) {
//Statements to be executed if the condition is true
} else {
//Statements to be executed if the condition is false
}
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");
}
}
Output
Number is greater than 5
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.
Learn more about Dart and Flutter
- List in Dart
- Abstract class and Abstract Methods in Dart
- Interface in Dart
- Constructors in Dart
- Arrow Function in Dart
- User Defined Function in Dart
- Functions in Dart
- Switch case in Dart
- Conditionals in Dart
- Operators in Dart
- Keywords in Dart
- Variables in Dart
- Data Types in Dart
Top comments (0)