-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlabel_continue.html
More file actions
65 lines (44 loc) · 1.31 KB
/
label_continue.html
File metadata and controls
65 lines (44 loc) · 1.31 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
<!DOCTYPE html>
<html lang="en-US">
<head>
<title> break and continue keywords</title>
<meta charset="UTF-8">
</head>
<body style="background-color:lightblue;">
<h1 style="text-align:center"> label reference keyword</h1>
<pre>
To label JavaScript statements you precede the statements with a label name and a colon:
label:
statements
The break and the continue statements are the only JavaScript statements that can "jump out of" a code block.
Syntax:
break labelname;
continue labelname;
The continue statement (with or without a label reference) can only be used to skip one loop iteration.
The break statement, without a label reference, can only be used to jump out of a loop or a switch.
With a label reference, the break statement can be used to jump out of any code block
A code block is a block of code between { and }.
</pre>
<script>
var arr = ["My","name","is","Nishkarsh","Raj","Khare"];
var i = 0;
var out = "";
//Problem here. I am trying to create a loop like structure using break,continue and label. Logic is there but it just does not give output
//Logic:
//Increment i till arr length and then break out of loop
//Until false, continue again from label.
l1:
{
out = out + arr[i] + " ";
i++;
//document.write(i);
if(i==arr.length)
{
break l1;
}
continue;
}
document.write(out);
</script>
</body>
</html>