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

# For and While Loops in the Standard Language Guide

> Iterate a fixed number of times or over query results with for loops, and repeat code while a condition holds with while loops in Standard.

Loops let you execute a block of code repeatedly without duplicating it. Standard provides two loop constructs: the `for` loop for iterating over a sequence or a set number of steps, and the `while` loop for repeating code as long as a condition remains true. Both are concise to write and easy to read.

## The For Loop

The `for` loop runs a block of code until it reaches the end of a given sequence. In Standard, that sequence can be a single integer — causing the block to execute that exact number of times — or an array of objects to iterate over. Use `@` inside the loop body to reference the current working object.

Print the loop index five times:

```text theme={null}
for: 5 {
    print @
}
```

Iterate through database results:

```text theme={null}
results [vhl]

#Print each vehicle in results
for: results {
    print @
}
```

## The While Loop

The `while` loop runs a block of code repeatedly until the condition you provide evaluates to `false`. Make sure the condition can eventually become false to avoid an infinite loop.

```text theme={null}
i 0
while: i < 5 {
    i++
    print @
}
```

<Warning>
  Always ensure the condition in a `while` loop will eventually evaluate to `false`. If the condition never changes, your program will loop indefinitely and become unresponsive.
</Warning>
