-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_loop.java
More file actions
43 lines (35 loc) · 1.17 KB
/
for_loop.java
File metadata and controls
43 lines (35 loc) · 1.17 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
public class for_loop {
// java For Loop
When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop:
SyntaxGet your own Java Server
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
Statement 1 is executed (one time) before the execution of the code block.
Statement 2 defines the condition for executing the code block.
Statement 3 is executed (every time) after the code block has been executed.
The example below will print the numbers 0 to 4:
Example
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
*/
//nested for loop
public static void main(String[] args) {
/* for (int i=1;i<=2;i++){
System.out.println("Outer"+i);
for(int j=1;j<=3;j++){
System.out.println("ineer"+j);
}
}*/
// for each loop
/*
for (type variableName : arrayName) {
// code block to be executed
}
String[] cars = {"VOlvo","bmw","audi","benz"};
for(String i : cars){
System.out.println(i);
}
}
}