Leaves the nearest enclosing for, for...in or while loop immediately.
break ends the loop it is in and the script carries on with the statement after the loop. Use it once you have the answer, so the rest of the passes are skipped. It affects only the innermost loop when loops are nested.
The value of the loop expression is the last value computed before the break.
Remarks
- break outside a loop is a compile error.
Example
//@version=6
indicator("Break", overlay = true)
distance = 0
for i = 1 to 50
if high[i] > high
distance := i
break
plot(distance, "Bars back to a higher high", color.orange, style = plot.style_columns)See also
Runs on Sidechair