metadeck
10/4/2018 - 1:27 PM

Beginners Dart - Loops

Beginners Dart - Loops

void main() {

  //Defining a boolean named wifi that will act as our parameter for the while statement.
  bool wifi = false;

  //Defining an integer that will count the number of times the loop has cycled.
  int noSignalCounter = 0;

  //A do while statement that defines its parameters at the end of the loop meaning that this loop will always cycle at least once.
  do {

    //Adding 1 to the value each time the loop cycles.
    noSignalCounter++;
    print("LOOP 1");
    print(noSignalCounter);

  //The parameters of the while loop.
  } while(noSignalCounter < 10);

  noSignalCounter = 0;
  while (wifi == false) {

    noSignalCounter++;
    print("LOOP 2");
    print(noSignalCounter);

    if(noSignalCounter > 9) {
      
      //Setting the value of while to true, breaking the if statement.
      wifi = true;

    }
  }
}