Break Statement in Dart Programming

  • Post author:
  • Post category:Dart
  • Post comments:2 Comments
Break Statement in Dart Programming

In this guide, we will discuss Break Statement in Dart Programming. The break statement is used to take the control out of a construct. Using break in a loop causes the program to exit the loop. Following is an example of the break statement.

Example

void main() { 
   var i = 1; 
   while(i<=10) { 
      if (i % 5 == 0) { 
         print("The first multiple of 5  between 1 and 10 is : ${i}"); 
         break ;    
         //exit the loop if the first multiple is found 
      } 
      i++; 
   }
}  

The above code prints the first multiple of 5 for the range of numbers within 1 to 10.

If a number is found to be divisible by 5, the if construct forces the control to exit the loop using the break statement. The following output is displayed on successful execution of the above code.

The first multiple of 5 between 1 and 10 is: 5 

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply