-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavabreakandcontinue.java
More file actions
73 lines (63 loc) · 1.27 KB
/
Javabreakandcontinue.java
File metadata and controls
73 lines (63 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package basics;
public class Javabreakandcontinue {
public static void main(String[] args) {
// TODO Auto-generated method stub
//break:jump out of loop
for(int i=0;i<10;i++)
{
if(i==4)
{
break;
}
System.out.println(i);
}
System.out.println("____________________________");
System.out.println("example for continue:");
System.out.println("____________________________");
for(int i=0;i<10;i++)
{
if(i==4)
{
continue; //when i=4 it the control goes to for loop without executing print statement
}
System.out.println(i);
}
System.out.println("______________________________");
System.out.println("example of braek and continue in while loop:");
System.out.println("_______________________________");
int i=0;
while(i<10)
{
System.out.println(i);
i++;
if(i==4)
{
break;
}
}
System.out.println("_______________________________");
int j=0;
while(j<10)
{
if(j==4)
{
j++;
continue;
}
System.out.println(j);
j++;
}
System.out.println("_______________________________");
int k=0;
while(k<10)
{
System.out.println(k);
k++;
if(k==4)
{
k++;
continue;
}
}
}
}