-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoopControl.java
More file actions
33 lines (32 loc) · 1018 Bytes
/
Copy pathLoopControl.java
File metadata and controls
33 lines (32 loc) · 1018 Bytes
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
/*
Loop control statements change execution from its normal sequence.
When execution leaves a scope, all automatic objects
that were created in that scope are destroyed.
1.break :
"Terminates the loop or switch statement and transfers execution to the statement
immediately following the loop or switch. "
2.continue :
"Causes the loop to skip the remainder of its body and immediately retest
its condition prior to reiterating. "
*/
public class LoopControl {
public static void main(String[] args) {
int [] numbers = {10, 20, 30, 40, 50};
System.out.println("Use Of break :");
for(int x : numbers ) {
if( x == 30 ) {
break;
}
System.out.print( x );
System.out.print("\n");
}
System.out.println("Use Of continue :");
for(int x : numbers ) {
if( x == 30 ) {
continue;
}
System.out.print( x );
System.out.print("\n");
}
}
}