- FOR LOOP
public class ForLoopExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("working");
for(int i=1; i<=50 ; i++){
int n = 2 * i;
System.out.println("2 * "+ i + " = " + n);
}
}
}
- WHILE LOOP
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("working");
int i = 0;
while (i < 50) {
i++;
int m = i*2;
System.out.println("2 * "+ i + " = " + m);
}
}
}
- DO WHILE LOOP
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("working");
int i = 0;
do {
i++;
int m = i*2;
System.out.println("2 * "+ i + " = " + m);
} while (i < 50);
}
}
OUTPUT:-
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20
2 * 11 = 22
2 * 12 = 24
2 * 13 = 26
2 * 14 = 28
2 * 15 = 30
2 * 16 = 32
2 * 17 = 34
2 * 18 = 36
2 * 19 = 38
2 * 20 = 40
2 * 21 = 42
2 * 22 = 44
2 * 23 = 46
2 * 24 = 48
2 * 25 = 50
2 * 26 = 52
2 * 27 = 54
2 * 28 = 56
2 * 29 = 58
2 * 30 = 60
2 * 31 = 62
2 * 32 = 64
2 * 33 = 66
2 * 34 = 68
2 * 35 = 70
2 * 36 = 72
2 * 37 = 74
2 * 38 = 76
2 * 39 = 78
2 * 40 = 80
2 * 41 = 82
2 * 42 = 84
2 * 43 = 86
2 * 44 = 88
2 * 45 = 90
2 * 46 = 92
2 * 47 = 94
2 * 48 = 96
2 * 49 = 98
2 * 50 = 100