Java continue statement Question 1

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    for (int count = 1; count <= 10; count++) // loop 10 times
    {/*from   w  ww.j av a  2 s  .  c  o  m*/
      if (count == 5)
        continue; // skip remaining code in loop body if count is 5

      System.out.printf("%d ", count);
    }

    System.out.printf("%nUsed continue to skip printing 5%n");
  }
}


1 2 3 4 6 7 8 9 10 
Used continue to skip printing 5

Note

continue statement terminating an iteration of a for statement.




PreviousNext

Related