File: BreakContinue.xml

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (44 lines) | stat: -rw-r--r-- 1,824 bytes parent folder | download | duplicates (7)
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE doc
  SYSTEM '../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../clonk.xsl"?>
<doc>
  <title>break and continue</title>
  <h>break and continue</h>
  <part>
    <text>The keywords <code>break</code> and <code>continue</code> are used for finer control of loops:</text>
    <text>
      <ul>
        <li id="break"><code>break</code> ends the enclosing loop. Execution is continued after the end of the loop.</li>
        <li id="continue"><code>continue</code> ends the current loop execution and continues with the next loop item from the beginning of the loop.</li>
      </ul>
    </text>
    <h>Example:</h>
    <code>for(var i = 0; i &lt; 10; i++) 
{
  <funclink>Log</funclink>(&quot;Number: %d&quot;, i);
  if(i &gt; 6) break;
  if(i &gt; 2) continue;
  Log(&quot;Number: %d (2. Ausgabe)&quot;, i);
}
Log(&quot;Final Number: %d&quot;,i);</code>
    <h>Output:</h>
    <code>Number: 0 
Number: 0 (2.Ausgabe)
Number: 1 
Number: 1 (2.Ausgabe)
Number: 2 
Number: 2 (2.Ausgabe)
Number: 3 
Number: 4 
Number: 5 
Number: 6 
Number: 7 
Final Number: 7</code>
    <text>This loops counts the variable <code>i</code> from 0 to 10.</text>
    <text>If the first three loop executions (i from 0 to 2) the value is displayed twice.</text>
    <text>From value 3 on <code>continue</code> is called after the first output. This will skip the current loop execution. The output is made only once.</text>
    <text>If value 7 is reached, <code>break</code> is called. <code>break</code> will, as opposed to <code>continue</code>, not only skip current loop execution but will break out of the whole loop. You can notice by seeing that the value of <code>i</code> is 7 at the end, not 11.</text>
  </part>
  <author>Peter</author><date>2001-07</date>
</doc>