-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path29_Loops.js
More file actions
64 lines (38 loc) · 1.09 KB
/
29_Loops.js
File metadata and controls
64 lines (38 loc) · 1.09 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
// Loops are also known as iterations or iterators .
// 1} for loop
const branch = 10
for ( let index = 0 ; index <= branch ; index++){
console.log(index)
}
// 2} nested loop : loop inside the loop
const myheroes = ["shaktima" , " nagraj " , "hanuman" , "flash ", "superman"]
for ( let i = 0 ; i < myheroes.length ; i++){
for ( let j = 0 ; j < 3 ; j++){
console.log(myheroes[i])
}
}
// 3} break and continue statements
for ( let i = 1 ; i <= 10 ; i++){
if ( i == 5){
break
}
console.log(`and the value of i is ${i}`)
}
for ( let i = 1 ; i <= 10 ; i++){
if ( i == 5){ // at i == 5 the loops will get continue to the next iteration without any execution
continue
}
console.log(`value of i is ${i}`)
}
// 4} while loop
let i = 0 // agar let ki jagah const declare krenge to nhi chalega because fir i ki value constant (not changable) ho jaygi
while ( i < 5){
console.log("Hello, Tarun")
i++
}
// 5} do while loop --> atleast runs once
let j = 1
do{
console.log("Hello World")
j++
}while( j < 5 )