> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Loops - break and continue

CRMScript has several statements that can alter the flow of `for` and `while` loops. This comes in addition to the loop conditions.

## Break statement

The `break` statement is a **loop control** mechanism that terminates the loop and jumps out of it to the 1st statement (if any) *after* the loop.

The definition is simply the keyword **break** followed by a semicolon.

```crmscript! theme={null}
Integer i = 1;
while(i < 10) {
  if(i == 5) {
    break;
  }
  printLine(i.toString());
  i++;
}
```

Based on the loop condition, this loop would print the numbers 1-9 in ascending order. However, due to the `break` statement, when `i` equals 5 we hit full stop. Thus the loop will print only numbers 1-4.

## Continue statement

The `continue`statement is a **loop control** mechanism that skips the remainder of the statements in the code block and fast-forwards to the next iteration of the loop. It goes directly to the next evaluation of the condition.

The definition is simply the keyword **continue** followed by a semicolon.

```crmscript! theme={null}
for(Integer i = 1; i < 10; i++) {
  if(i == 3) {
    continue;
  }
  printLine(i.toString());
}
```

Based on the loop condition, this loop would print the numbers 1-9 in ascending order. However, due to the `continue` statement, when `i` equals 3 we short-circuit the loop and go directly to `i++`. Thus the loop will print all numbers 1-9 **except** 3.

<Danger>
  As always, it is crucial that you **update the counter** of `while` loops. Pay attention to where you place your update in relation to the `continue` statement!
</Danger>


## Related topics

- [Loops - for](/en/automation/crmscript/fundamentals/for-loops.md)
- [File](/en/automation/crmscript/reference/CRMScript.Native.File.md)
- [Functions](/en/automation/crmscript/fundamentals/functions.md)
- [Loops - while](/en/automation/crmscript/fundamentals/while-loops.md)
- [Loops - foreach](/en/automation/crmscript/fundamentals/foreach-loops.md)
- [Break Actor Link](/en/api/reference/restful/agent/erpsync_agent/break-actor-link.md)
