Continue Statement in Java.
Continue Statement is generally utilized inside circles. At whatever point it is experienced inside a Loops,
control straightforwardly leaps to the start of the circle for next cycle, skirting the execution of proclamations inside circle's body for the current emphasis.
This is especially helpful when you need to proceed with the circle however don't need the remainder of the statements(after proceed with articulation) in circle body to execute for that specific cycle.
Synatx:
Continue word followed by semi colon.
proceed;
Model: proceed with explanation inside for circle
public class ContinueExample {
public static void main(String args[]){
for (int j=0; j<=6; j++)
{
on the off chance that (j==4)
{
proceed;
}
System.out.print(j+" ");
}
}
}
Output:
0 1 2 3 5 6
As you may have seen, the worth 4 is absent in the yield, why? since when the worth of variable j is 4, the program experienced a proceed with explanation,
which takes it to leap toward the start of for circle for next cycle, skirting the assertions for current emphasis (that is the explanation println didn't execute when the worth of j was 4).
flow Diagram of Continue Statement
Proceed with Statement
Model: Use of proceed in While circle
Same thing you can see here. We are repeating this circle from 10 to 0 for counter worth and when the counter worth is 7 the circle skirted the print articulation and began next emphasis of the while circle.
public class ContinueExample2 {
public static void main(String args[]){
int counter=10;
while (counter >=0)
{
on the off chance that (counter==7)
{
counter- - ;
proceed;
}
System.out.print(counter+" ");
counter- - ;
}
}
}
Output:
10 9 8 6 5 4 3 2 1 0
Illustration of proceed in do-While circle
public class ContinueExample3 {
public static void main(String args[]){
int j=0;
do
{
in the event that (j==7)
{
j++;
proceed;
}
System.out.print(j+ " ");
j++;
}while(j<10);
}
}
Yield:
0 1 2 3 4 5 6 8 9
0 Comments:
Post a Comment