Back to Sway

break

docs/reference/src/documentation/language/control-flow/looping/break.md

0.71.0467 B
Original Source

break

break is a keyword available for use inside of a while loop and it is used to exit out of the loop before the looping condition is met.

sway
{{#include ../../../../code/language/control_flow/src/lib.sw:break_example}}

In the example above the while loop is set to iterate until counter reaches the value of 10 however the if expression will break out of the loop once counter reaches the value of 6.