continue statement terminating an iteration of a for statement - Java Language Basics

Java examples for Language Basics:continue

Description

continue statement terminating an iteration of a for statement

Demo Code

public class Main 
{
   public static void main(String[] args)
   {/*from www  .j  av  a2  s .  co  m*/
      for (int count = 1; count <= 10; count++) // loop 10 times
      {  
         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");
   }
}

Result


Related Tutorials