Jump to content

Continue (Java)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Bluemoose (talk | contribs) at 21:22, 5 January 2006 (AWB Assisted clean up and fix c++ links). 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 in the same way that it does in the C Programming Language and also C++. When used inside of while and for loops it will skip the remaining instructions in the loop and begin on the next iteration in the loop.

The following prints only 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" followed by a space
        System.out.print(i + ' ');
   }

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