assistance-engine/docs/developer.avapframework.com/chapter9_34.md

25 lines
991 B
Markdown

## Break Statement
In AVAP, the break statement is used to terminate the closest enclosing loop. The syntax for the break statement is as follows:
```javascript
break()
```
When a break statement is encountered, it causes the loop to exit immediately, regardless of the loop's condition or any remaining iterations. This effectively transfers control to the statement following the loop.
The break statement is typically used within `for` or `while` loops to provide a way to exit the loop prematurely based on a certain condition.
```javascript
addVar(_status, "OK")
startLoop(idx, 0, 9)
if(idx, 4, "==")
idx = -1
break()
end()
endLoop()
addResult(idx) addStatus("OK")
```
In this example, the loop will terminate when `i` equals 5, and "Loop ended" will be printed. The numbers 0 through 4 will be printed before the loop is exited.