Difference between revisions of "Manual:DIL Manual/continue"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="dccont"></span>
+
= continue =
−
'''continue:'''
+
'''Instruction.''' Skips the rest of the loop's statement and starts its next round.
−
    The continue statement makes you jump to the top
 
−
    of any loop you're currently in.
 
  
−
  '''Example:'''
+
  continue;
  
−
<nowiki>
+
In a [[Manual:DIL Manual/while()|while]] it goes back to the loop's test; in a [[Manual:DIL Manual/foreach()|foreach]] it goes on with the next unit. It acts on the innermost loop around it.
  
−
  dilbegin foo();
+
== Notes ==
−
  code
+
* Outside a loop vmc stops with "Using continue outside loop".
−
dilend</nowiki>
+
* In a <code>while</code>, take the step before the <code>continue</code>. A <code>continue</code> that skips <code>u := u.next;</code> runs the same round again and again, until the server stops the program for an endless loop.
  
−
---~---~---~---~---~---~---~---~---
+
== Example ==
−
<span id="dccont"></span>
+
<pre>
−
'''continue:'''
+
dilbegin carried_weight();
−
    The continue statement makes you jump to the top
+
var
−
    of any loop you're currently in.
+
  u : unitptr;
 +
  w : unitptr;
 +
  n : integer;
 +
code
 +
{
 +
  u := self.inside;
 +
  while (u != null)
 +
  {
 +
      w := u;
 +
      u := u.next;
 +
      if (w.equip != 0)
 +
        continue;
 +
      n := n + w.weight;
 +
  }
 +
  exec("say What I carry weighs " + itoa(n) + ", not counting what I wear.", self);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Adds up the weight of what an NPC carries but doesn't wear. The step to the next unit comes before the <code>continue</code>.
  
−
'''Example:'''
+
== See also ==
−
 
+
* [[Manual:DIL Manual/break|break]]
−
<nowiki>
+
* [[Manual:DIL Manual/while()|while()]]
−
 
+
* [[Manual:DIL Manual/foreach()|foreach()]]
−
  dilbegin foo();
 
−
  code
 
−
dilend</nowiki>
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:16, 14 November 2026

continue

Instruction. Skips the rest of the loop's statement and starts its next round.

continue;

In a while it goes back to the loop's test; in a foreach it goes on with the next unit. It acts on the innermost loop around it.

Notes

  • Outside a loop vmc stops with "Using continue outside loop".
  • In a while, take the step before the continue. A continue that skips u := u.next; runs the same round again and again, until the server stops the program for an endless loop.

Example

dilbegin carried_weight();
var
   u : unitptr;
   w : unitptr;
   n : integer;
code
{
   u := self.inside;
   while (u != null)
   {
      w := u;
      u := u.next;
      if (w.equip != 0)
         continue;
      n := n + w.weight;
   }
   exec("say What I carry weighs " + itoa(n) + ", not counting what I wear.", self);
   quit;
}
dilend

Adds up the weight of what an NPC carries but doesn't wear. The step to the next unit comes before the continue.

See also