Continue Statement Example Program in Dart


This program demonstrates the use of the continue statement inside a for loop to skip even numbers and print only odd numbers from 0 to 9. Here's how the program works:

  • The for loop is initialized with i=0 and the loop condition is i<10. This means that the loop will iterate 10 times, from 0 to 9.
  • Inside the loop, the if statement checks if i is even or not by using the modulus operator (i%2==0) . If i is even, the continue statement is executed, which skips the rest of the code inside the loop and moves on to the next iteration.
  • If i is odd, the code inside the if statement is skipped and the print statement outside the if statement is executed, which prints the value of i.
  • The loop continues until i is no longer less than 10, and the program ends.

Source Code

//Printing Odd Numbers 
void main()
{
  for(var i=0;i<10;i++)
  {
    if(i%2==0)
    continue;
    print("Odd Nos : $i");
  }
}
To download raw file Click Here

Output

Odd Nos : 1
Odd Nos : 3
Odd Nos : 5
Odd Nos : 7
Odd Nos : 9