-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopsConcept.java
More file actions
112 lines (89 loc) · 2.06 KB
/
LoopsConcept.java
File metadata and controls
112 lines (89 loc) · 2.06 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package JavaSessions;
public class LoopsConcept {
public static void main(String[] args) {
//1 to 10:
//1. while:
int i = 1;
while(i<=10) {
System.out.println(i);//1 2 3 4 5 .....10
i++;
//++i;
//i=i+1;
}
int k = 1;
while(k<=100) {
System.out.println(k);
if(k % 5 == 0) {
System.out.println("hii");
}
k++;
}
//Taj Hotel -- welcome
// while(true) {
// System.out.println("welcome to Hotel Taj");
// }
// boolean flag = false;
// while(flag) {
//
// }
//use cases for while:
//1. when the number of interations are not fixed -- prefer while loop
//2. Amazon -- total products -- 1 to 100, 1 to 200, 1 to 300
//3. checking the element present on the pages -- while loop
//4. pagination
boolean t = true;
while(t) {
System.out.println("welcome");
t = false;
}
System.out.println("------------------------");
//2. for loop:
//1 to 10
for(int p=1; p<=10; p++) {
System.out.println(p);//1 2 3 4 5 ...10
}
// for(;;) {
// System.out.println("bye");
// }
for(char c='a'; c<='z'; c++) {
System.out.println(c+ " ");
}
for(int c='a'; c<='z'; c++) {
System.out.println(c);
}
for(double d = 1.1; d<=10.0; d++) {
System.out.println(d);
}
// for(String s = "test"; s.equals("selenium"); s++) {
// System.out.println(s);
// }
//use cases for for loop:
//1. when we are sure about the total number of iterations
//2. iterating arrays, arraylist -- for loop
//3. data driven - get the data from Excel -- total rows = 10
System.out.println("-----");
//do-while:
int r = 1;
do {
System.out.println(r);
r++;
}
while(r<=10);
//use cases for do-while:
//1. pagination:
//2. check the title of the page
//loop with break:
for(int h=1; h<=10; h++) {
System.out.println(h);
if(h % 5 == 0) {
System.out.println("Hi");
break;
}
}
//get the list of all footer links
//start a loop
//put a condition to check the link text is equal to "amazon"
//click on that element
//break the loop
}
}