The if Statement
Let’s learn to use the if statement in Dart.
We'll cover the following
Introduction
The if
statement allows you to incorporate conditions in your code which need to be fulfilled before the code can execute.
Moving away from the world of computers, let’s imagine you wake up in the morning and get ready to go out. When you reach the door, you’re not sure if it’s raining outside or not. If it is raining outside, you will take an umbrella with you. If it is not raining, you wouldn’t want to take an umbrella with you, so you do nothing and just leave. Your final decision is conditional based on the weather outside. This is the same way conditional statements work.
Conditional statements are incredibly powerful as they take the state of the program into consideration and act accordingly. This provides a decision-making capability to the programmer.
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy