Loop Control Statements

Loop Control Statements

There are two loop controls statements in dart. They are break and continue. let’s get to know about them.

break Statement

The break statement is one of the loop controls statement in dart.The statement is used to control out of a construct. Using break in a loop causes the program to exit fully out of the loop.

Following is an example of break statement

void main(){
  var num = 10;
  while(num<=10){
    if(num % 2 == 0){
      print(num);
     
      break; //exit the loop if the expression is true
    }
     num--;
  }
}

The output of the above code is:

10

code Try Yourself

continue Statement

The continue is another loop control statement in dart. The statement skips an specific statement of the code block rather than exit of the loop fully and continue the rest of the code.

Following is an example of continue statement

void main(){
  var num = 10;
  while(num<=10){
    if(num % 2 == 0){
      print(num);
      continue; //exit the loop if the expression is true
    }
     num--;
  }
}

The output of the above code is:

10 
6
4
2

code Try Yourself