Difference between revisions of "Manual:DIL Manual/break"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = break = | ||
| + | '''Instruction.''' Leaves the loop it is in. | ||
| + | break; | ||
| − | + | Jumps to the first statement after the innermost [[Manual:DIL Manual/while()|while]] or [[Manual:DIL Manual/foreach()|foreach]] around it. These are DIL's only loop statements. | |
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| + | * Outside a loop vmc stops with "Using break outside loop". | ||
| + | * In nested loops it only leaves the innermost one. | ||
| + | * Leaving a <code>foreach</code> early is fine: the units it hadn't reached are dropped when the next <code>foreach</code> starts or the template returns. | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin wake_sleeper(); | |
| − | code | + | var |
| + | u : unitptr; | ||
| + | code | ||
| + | { | ||
| + | u := self.outside.inside; | ||
| + | while (u != null) | ||
{ | { | ||
| − | + | if ((u.type == UNIT_ST_PC) and (u.position == POSITION_SLEEPING)) | |
| − | |||
break; | break; | ||
| − | + | u := u.next; | |
| − | |||
| − | |||
} | } | ||
| − | dilend</ | + | if (u != null) |
| + | exec("wake " + u.name, self); | ||
| + | quit; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | An NPC looks through its room for the first sleeping player and wakes them. After the loop <code>u</code> is that player, or null when there was none. | ||
| − | + | == See also == | |
| + | * [[Manual:DIL Manual/continue|continue]] | ||
| + | * [[Manual:DIL Manual/while()|while()]] | ||
| + | * [[Manual:DIL Manual/foreach()|foreach()]] | ||
Latest revision as of 23:16, 14 November 2026
Contents
break
Instruction. Leaves the loop it is in.
break;
Jumps to the first statement after the innermost while or foreach around it. These are DIL's only loop statements.
Notes
- Outside a loop vmc stops with "Using break outside loop".
- In nested loops it only leaves the innermost one.
- Leaving a
foreachearly is fine: the units it hadn't reached are dropped when the nextforeachstarts or the template returns.
Example
dilbegin wake_sleeper();
var
u : unitptr;
code
{
u := self.outside.inside;
while (u != null)
{
if ((u.type == UNIT_ST_PC) and (u.position == POSITION_SLEEPING))
break;
u := u.next;
}
if (u != null)
exec("wake " + u.name, self);
quit;
}
dilend
An NPC looks through its room for the first sleeping player and wakes them. After the loop u is that player, or null when there was none.