Jump to content

Continue (Java)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mako 5 (talk | contribs) at 07:22, 13 December 2005 ([[Java programming language|Java]]). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The continue keyword works in Java keywords in the same way that it does in the C Programming Language and also C++. When used inside of while and for loops where it will skip the remaining instructions in the loop and begin on the next iteration in the loop.

The following only prints even numbers between and including 0 and 10

for(int i=0; i<=10; i++) {

   //skips the print statement if i is not even
   if(i % 2 != 0)
       continue;
   //prints the integer "i"
   System.out.println(i);

}


The result of this loop is 0 2 4 6 8 10