marqdo

05-loopok

structure/05-loop.mq.md

Structure

fn · h1main
comment

Inside a function body, - starts a loop (not a parameter).

comment

Countdown:

bind `n` = 3
while`n` > 0
call> print text=`n`
bind `n` = `n` - 1
comment

Walk a table (tables are collections):

bind `basket` = [apple, pear]
foreach[fruit](basket)
call> print text=today `fruit`
Functions
Variables
  • basket list · 2
    #value
    1apple
    2pear
  • fruit text
    pear
  • n int
    0

Execution

3 2 1 today apple today pear

Source

---
title: Loops
description: Condition loops and table walks
---

# main

Inside a function body, `-` starts a loop (not a parameter).

Countdown:

**`n` = 3**

- `n` > 0
  > print text=`n`
  **`n` = `n` - 1**

Walk a table (tables are collections):

`basket` =

| fruit |
|-------|
| apple |
| pear |

- [fruit](basket)
  > print text=today `fruit`

Variable