Manual:DIL Manual/break

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:16, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 foreach early is fine: the units it hadn't reached are dropped when the next foreach starts 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.

See also