Warning: Undefined array key "lang_code" in /home/pmfnldmy/public_html/androidatc/ap/extension/classes/common.php on line 800
For Loops

For Loops

A for statement provides a compact way to iterate over a range of values.
Programmers often refer to it as the "for-loop" because it repeatedly loops until a particular condition is satisfied.

The following is an example of how the for-loop works:

main() {
  // for loop
  for (var i = 0; i < 5; i++) {
    print("i= $i");
  }
}

Note: i++ means i=i+1 (or increment by 1).

When the program starts, the i variable has a value = 0. However, when the Dart compiler runs the code below within the "for" loop braces and finishes its loop, the "i" variable takes the second value which is 1, and so on until it takes the last value which is 4 here. When the "i" variable takes its final value, the Dart compiler will resume its work outside the "for" loop braces. When you run the Dart program, you will get the following result:

For Loops

* This topic is a part of lesson 2 of Flutter Application Development course. For more information about this course, click here.