if continue java code example
Example 1: break java
//Conclusion
break == jump out side the loop
continue == next loop cycle
return == return the method/end the method.
for(int i = 0; i < 5; i++) {
System.out.println(i +"");
if(i == 3){
break;
}
}
System.out.println("finish!");
/* Output
0
1
2
3
finish!
*/
Example 2: Continue statement in java
// continue in java example
import java.util.*;
public class ContinueJavaExample
{
public static void main(String[] args)
{
for(int a = 1; a <= 10; a++)
{
if(a % 2 != 0)
{
continue;
}
System.out.println(a + " ");
}
}
}
Example 3: continue in java
int i = 0;
while (i < 10) {
if (i == 4) {
i++; //why do I need this line ?
continue;
}
System.out.println(i);
i++;
}