# For Loops

`for` loops are the most concise loop construct.

For `for` loops, **parenthesis are required**, this is described in the [Control Flow](https://github.com/cheddar/docs/tree/48c6d425cd54768a27ab1dc5d3df0eef0c8cee40/control_flow.md) section.

There syntax is highly resemblant of their C counterpart:

```go
for (var i := 0; i < 5; i++) {
    print "i is: #{i}"
}
```

The syntax of the `for` loop is:

```go
for (<initalization>; <condition>; <afterthought>) {
    [code block]
}
```

Essentially the way this works is:

```go
execute initalization
while condition evaluates to true
    execute code block
    execute afterthought
```

The output of the first `for` example would be:

```
i is: 0
i is: 1
i is: 2
i is: 3
i is: 4
i is: 5
```

This is because the variable `i` is initialized to `0` at the beginning. Then, because `i` is less then `5`, it will keep running the code block until `i` is not less than `5`. This happens because the `i++` increases `i` everytime, after, the code block (i.e. the `print`) is executed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cheddar.vihan.org/docs/control-flow/loops/for-loops.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
