-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathbreakContinueReturn.js
More file actions
35 lines (29 loc) · 787 Bytes
/
breakContinueReturn.js
File metadata and controls
35 lines (29 loc) · 787 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
34
35
//---------------- Break ---------------
//It will run the loop till break statement only and get out of entire loop
for(var i = 0; i < 10; i++){
console.log(i);
if(i == 5){
break;
}
}
console.log("Last value of i is : ",i);//Not print after 5
//---------------- Continue -------------------
//It will just skip the next code after the continue
for(var i = 0; i < 10; i++){
console.log(i);
if(i == 5){
continue;//This is not show done for 5
}
console.log("Done");
}
//----------------- Return----------------------
//This work same as break but while in function
function myfunction(){
for(var i = 0; i < 10; i++){
console.log(i);
if(i == 5){
return;//Not print after 5
}
}
}
myfunction();