Control flows and looping
Before we can finish exploring the main
method in DartPad, we need to know how to control the flow of code execution. This is done through a series of control flow statements. These are very similar to those in other programming languages, so let’s see what they look like in Dart.
if/else
Dart supports the standard if
, else if
, else
decision structure. It also supports if
statements without curly brackets, which are especially useful during Flutter widget definitions.
In these if
statements, the next expression is evaluated if the condition is true
. You can see an example of this in the following code snippet:
String winners = "Middlesbrough"; if (winners == "Everton") { print("Everton win"); } else if (winners == "Middlesbrough") { print("Middlesbrough win"); } else { print("Draw"); } // Prints Middlesbrough win if (winners == "Middlesbrough...