Home of LDMud
LPC has the same control flow statements as C (and one addition foreach
):
if
while
do-while
loop where the loop body is
at least executed once and the condition is evaluated first after
the first loop.
for
for
loops contain three expressions and a loop body.
The first expression is executed at the beginning of the loop.
The second expression is evaluated each time before the loop body
is executed. If this expression yields zero then the loop will end.
The third expression is executed at the end of each loop.
foreach
foreach
iterates over a range, which can be
an array, mapping, struct (iterating over each member variable),
string (iterating over each character of the string), or an
integer range.
switch
switch
executes code blocks depending on a value.
When there is no break
statement at the end of a case
block
then the following block is executed as well.
break
break
exits the innermost while
, for
, foreach
loop, or switch
block.
continue
continue
will continue the execution from the beginning of the innermost while
, for
, or foreach
loop.
In a for
loop the third expression (loop end) and second expression (loop condition) are evaluated. If the loop condition yields zero,
the loop ends. Similarly the loop condition of while
is evaluated. In foreach
loops the loop starts with the next value.
return
return
exits the current function and optionally returns a value.
yield
yield
suspends the execution of a coroutine and optionally passes
a value to the caller or another coroutine.
await
await
suspends the execution of a coroutine until another coroutine
finishes and optionally passes a value.