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.
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. š
- My Site
- My Blogs
- Medium
- Github
- Stack overflow or just mail me at jd.tillu@gmail.com