loop loop
loop loop
Function
loop is a reserved compatibility form for an unconditional infinite loop. New code can also use for {} to express an infinite loop.
Syntax
loop { if condition { break } } loop:label { continue:label }
Example
i = 0 loop { if i >= 3 { break } println i i += 1 }
Notes
- It is recommended to use
for {}first for new codes, andloopwill continue to be compatible. -
loopusually must be matched withbreakin the loop body, otherwise the program will keep running. -
continuewill skip the subsequent statements of this round and go directly to the next round. - The
loopstatement itself returnsempty.