Rust loops: Difference between revisions
From wikinotes
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
= Breaking/Continuing etc. = | = General = | ||
<blockquote> | |||
== Breaking/Continuing etc. == | |||
<blockquote> | <blockquote> | ||
<syntaxhighlight lang="rust"> | <syntaxhighlight lang="rust"> | ||
Line 6: | Line 8: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Breaking/Continuing etc. --> | </blockquote><!-- Breaking/Continuing etc. --> | ||
== Loop Labels == | |||
<blockquote> | |||
Loops can be assigned labels, so that you can target which loop to break out of. | |||
<syntaxhighlight lang="rust"> | |||
'outer_loop: loop { | |||
loop { | |||
break 'outer_loop; | |||
} | |||
} | |||
</syntaxhighlight> | |||
</blockquote><!-- Loop Labels --> | |||
</blockquote><!-- General --> | |||
= loop = | = loop = |
Revision as of 14:46, 7 February 2023
General
Breaking/Continuing etc.
break; // exit loop continue; // skip to next iteration of loopLoop Labels
Loops can be assigned labels, so that you can target which loop to break out of.
'outer_loop: loop { loop { break 'outer_loop; } }
loop
loop { // loop forever }