Break: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
m wording
Document CON's weird 'break' behavior inside 'while' loops.
Line 1: Line 1:
A single '''break''' command can be
A single '''break''' command can be
used to stop code after the '''break''' from executing. Can also be used to exit a [[state]] early. Also used inside [[switch]] blocks to close '''[[case]]''' statements.
used to stop code after the '''break''' from executing. Can also be used to exit a [[state]] early. Also used inside [[switch]] blocks to close '''[[case]]''' statements.
Inside '''while''' loops, a '''break''' transfers control to the beginning of the loop where the condition for continuing the iteration is checked. This is in contrast to most imperative programming languages, where a '''break''' inside a loop transfers control to just after the end of the loop body (thus "breaking" it). For example, in CON, the snippet
    setvar j 0
    whilevarn j 3
    {
        addvar j 1
        userquote 500
        break  // while is inner: "continue"
    }
makes quote 500 be displayed ''three'' times in total.


[[Category:Duke3D 1.3/1.5 commands]]
[[Category:Duke3D 1.3/1.5 commands]]

Revision as of 12:17, 21 April 2014

A single break command can be used to stop code after the break from executing. Can also be used to exit a state early. Also used inside switch blocks to close case statements.

Inside while loops, a break transfers control to the beginning of the loop where the condition for continuing the iteration is checked. This is in contrast to most imperative programming languages, where a break inside a loop transfers control to just after the end of the loop body (thus "breaking" it). For example, in CON, the snippet

   setvar j 0
   whilevarn j 3
   {
       addvar j 1
       userquote 500
       break  // while is inner: "continue"
   }

makes quote 500 be displayed three times in total.