0

How can we use continue statement

how is it used with wat is it used and everything about continue statement

7th Dec 2016, 6:07 AM
TOYS JUNCTION
TOYS JUNCTION - avatar
1 Antwort
0
A continue in java can be used in loops (while, do-while, for, for-each) to skip to the end of the loop. So say you want to skip every even number from 0-100, but if it is uneven, do something else. Instead of having an if-else statement you can have one if statement and a continue. Example: for (int i = 0; i < 100; i++) { if (i % 2 == 0) continue; // If 'i' is uneven do stuff ... } It works like a return statement for a method. You can also use continue with nested loops and labels, but I am sure you can find information about that elsewhere. The basic idea is to have a label for a loop to identify which loop to continue.
7th Dec 2016, 10:59 AM
Daniel Riissanen
Daniel Riissanen - avatar