---
title: Control your loops like a champ
description: "[SPIN2](https://obex.parallax.com/code-language/spin2/) ## Introduction The Propeller 2 SPIN2 language has a new feature added in version 52 to extend the flexibility of the REPEAT loop control commands, NEXT and QUIT. ## Explainer Within REPEAT constructs, NEXT and QUIT are two special…"
url: "https://obex.parallax.com/docs/chips-tips/propeller-2/control-your-loops-like-a-champ/"
updated: "2025-10-10"
category: OBEX
---

# Control your loops like a champ

[SPIN2](https://obex.parallax.com/code-language/spin2/)

## Introduction

The Propeller 2 SPIN2 language has a new feature added in version 52 to extend the flexibility of the REPEAT loop control commands, NEXT and QUIT.

## Explainer

Within REPEAT constructs, NEXT and QUIT are two special instructions which can be used to change the course of execution. NEXT will immediately branch to the point in the REPEAT construct where the decision to loop again is made, while QUIT will exit the REPEAT construct and continue after it.

These instructions are usually used conditionally:

```text
REPEAT
  {indented code}
  IF {condition}				- Optionally force the next iteration of the REPEAT
    NEXT
  {indented code}
  IF {condition}				- Optionally quit the REPEAT
    QUIT
  {indented code}
```

NEXT and QUIT can each be followed by an integer value 1..16 to alter the nesting level at which they are to occur.

If no integer value is expressed, the default value of 1 is used, which means the current nesting level. The value 2 would mean the outer nesting level, while three would mean the next outer nesting level, and so on.

## Nested Example

```text
REPEAT
  {outer loop code}
  REPEAT 5
    {indented code}
    IF {condition}				- Optionally force the next iteration of the REPEAT
      NEXT
    {indented code}
    IF {condition}				- Optionally quit the OUTER REPEAT loop, 2 nested levels up
      QUIT 2
    {indented code}
```

---

## Resources

[Parallax Propeller 2 - Spin2 Language Documentation](https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/preview)

---
