2016-03-26 00:47:20 +01:00
# Break
2016-04-02 01:22:47 +02:00
Break statement; exit a for or while loop.
2016-03-26 00:47:20 +01:00
2017-03-07 19:17:01 +01:00
### @parent javascript/language
2016-03-26 00:47:20 +01:00
2017-03-07 19:17:01 +01:00
Exit a [while ](/javascript/while ) or [for ](/reference/loops/for ) loop before the loop is complete.
2016-03-26 00:47:20 +01:00
### Touch Develop syntax
**break**
### Example: count to a random number
The following example counts from 0 to a random number from 0-9. When the for loop counter equals the random number (`i = x`), the `break` statement exits the loop:
```
let x = Math.random(10)
for (let i = 0; i < 10 ; i + + ) {
if (i == x) {
break
} else {
basic.showNumber(i, 0)
basic.pause(500)
}
}
```
### See also
2017-03-07 19:17:01 +01:00
[for ](/reference/loops/for ), [while ](/javascript/while )
2016-03-26 00:47:20 +01:00