-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjump-statements.js
78 lines (48 loc) · 1.56 KB
/
jump-statements.js
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
/* jump statements */
//jump statements are used to jump the execution to the new location.
/* 1.break */
//syntax
//break;
//example
for(let i=1; i<=5; i++){
if (i==3) break; //break statement when i become 3.
//continue; (will break at 3 and start again till 5)
console.log(i);
}
//2. continue(will execute the whole loop without terminating the loop)
//syntax
//continue;
//continue labelname;
//example
/*
let x=0;
while(x<10){
x++; //increase the value of 1 by post increment.
if(x==5){
continue; //continue will skip the rest of the code(skip 5 on console)
}
console.log(x);
}
*/
//3. return statement
//syntax
//return expression;
//example
/*
function add(x){
return x+x;
}
console.log(add(3));
*/
/* labeled statements */
//syntax
//identifier:statement;
//example
/*
let a=1;
//creating label
label:while(a==1){
console.log(a);//prints one infinite times.
break label; //breaks the loop execution and prints 1.
}
*/