Renderingen-US

Loops

for iterates. The word after it is the mode — what kind of traversal this is — and it is required, so a loop always says what it walks.

ModeWalks
fromthe values of a collection
refthe keys of a table, or the indices of a list
aba numeric range

Over values#

reader locale
faber format --locale en — English reader surface
main {
    const list<int> numeri  [1, 2, 3]
    for from numeri const n {
        print n
    }
}
faber format --locale la — canonical Faber
incipit {
    fixum lista<numerus> numeri  [1, 2, 3]
    itera ex numeri fixum n {
        nota n
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    คงที่ รายการ<จำนวน> numeri  [1, 2, 3]
    วน ออก numeri คงที่ n {
        บันทึก n
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    常量 列表<整数> numeri  [1, 2, 3]
    遍历 取自 numeri 常量 n {
        显示 n
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    定值 列表<整數> numeri  [1, 2, 3]
    遍歷 取自 numeri 定值 n {
        註記 n
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    hằng danh_sách<số> numeri  [1, 2, 3]
    lặp từ numeri hằng n {
        ghi_chú n
    }
}
faber format --locale ar — Arabic
بداية {
    ثابت قائمة<عدد> numeri  [1, 2, 3]
    كرر من numeri ثابت n {
        اعرض n
    }
}
faber format --locale hi — Hindi
आरंभ {
    स्थिर सूची<संख्या> numeri  [1, 2, 3]
    दोहराओ सेवन numeri स्थिर n {
        दिखाओ n
    }
}

Over keys#

reader locale
faber format --locale en — English reader surface
main {
    const map<string, string> persona  { "nomen": "Marcus", "urbs": "Roma" }
    for ref persona const clavis {
        print clavis, persona[clavis]
    }
}
faber format --locale la — canonical Faber
incipit {
    fixum tabula<textus, textus> persona  { "nomen": "Marcus", "urbs": "Roma" }
    itera de persona fixum clavis {
        nota clavis, persona[clavis]
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    คงที่ ตาราง<ข้อความ, ข้อความ> persona  { "nomen": "Marcus", "urbs": "Roma" }
    วน จาก persona คงที่ clavis {
        บันทึก clavis, persona[clavis]
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    常量 映射<文本, 文本> persona  { "nomen": "Marcus", "urbs": "Roma" }
    遍历 借自 persona 常量 clavis {
        显示 clavis, persona[clavis]
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    定值 表格<文字, 文字> persona  { "nomen": "Marcus", "urbs": "Roma" }
    遍歷  persona 定值 clavis {
        註記 clavis, persona[clavis]
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    hằng bảng<văn_bản, văn_bản> persona  { "nomen": "Marcus", "urbs": "Roma" }
    lặp ra persona hằng clavis {
        ghi_chú clavis, persona[clavis]
    }
}
faber format --locale ar — Arabic
بداية {
    ثابت جدول<نص, نص> persona  { "nomen": "Marcus", "urbs": "Roma" }
    كرر عن persona ثابت clavis {
        اعرض clavis, persona[clavis]
    }
}
faber format --locale hi — Hindi
आरंभ {
    स्थिर तालिका<पाठ, पाठ> persona  { "nomen": "Marcus", "urbs": "Roma" }
    दोहराओ से persona स्थिर clavis {
        दिखाओ clavis, persona[clavis]
    }
}

The same mode gives you list indices, which is what you want when the position matters as much as the value:

reader locale
faber format --locale en — English reader surface
main {
    const list<int> numeri  [10, 20, 30]
    for ref numeri const index {
        print index, numeri[index]
    }
}
faber format --locale la — canonical Faber
incipit {
    fixum lista<numerus> numeri  [10, 20, 30]
    itera de numeri fixum index {
        nota index, numeri[index]
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    คงที่ รายการ<จำนวน> numeri  [10, 20, 30]
    วน จาก numeri คงที่ index {
        บันทึก index, numeri[index]
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    常量 列表<整数> numeri  [10, 20, 30]
    遍历 借自 numeri 常量 index {
        显示 index, numeri[index]
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    定值 列表<整數> numeri  [10, 20, 30]
    遍歷  numeri 定值 index {
        註記 index, numeri[index]
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    hằng danh_sách<số> numeri  [10, 20, 30]
    lặp ra numeri hằng index {
        ghi_chú index, numeri[index]
    }
}
faber format --locale ar — Arabic
بداية {
    ثابت قائمة<عدد> numeri  [10, 20, 30]
    كرر عن numeri ثابت index {
        اعرض index, numeri[index]
    }
}
faber format --locale hi — Hindi
आरंभ {
    स्थिर सूची<संख्या> numeri  [10, 20, 30]
    दोहराओ से numeri स्थिर index {
        दिखाओ index, numeri[index]
    }
}

Over a range#

builds a range. The lower bound is included, the upper bound is not.

reader locale
faber format --locale en — English reader surface
main {
    for range 03 const i {
        print i
    }
}
faber format --locale la — canonical Faber
incipit {
    itera ab 03 fixum i {
        nota i
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    วน ช่วง 03 คงที่ i {
        บันทึก i
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    遍历 范围 03 常量 i {
        显示 i
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    遍歷 範圍 03 定值 i {
        註記 i
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    lặp khoảng 03 hằng i {
        ghi_chú i
    }
}
faber format --locale ar — Arabic
بداية {
    كرر نطاق 03 ثابت i {
        اعرض i
    }
}
faber format --locale hi — Hindi
आरंभ {
    दोहराओ सीमा 03 स्थिर i {
        दिखाओ i
    }
}

per sets the step:

reader locale
faber format --locale en — English reader surface
main {
    for range 010 step 2 const i {
        print i
    }
}
faber format --locale la — canonical Faber
incipit {
    itera ab 010 per 2 fixum i {
        nota i
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    วน ช่วง 010 ต่อ 2 คงที่ i {
        บันทึก i
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    遍历 范围 010  2 常量 i {
        显示 i
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    遍歷 範圍 010  2 定值 i {
        註記 i
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    lặp khoảng 010 qua 2 hằng i {
        ghi_chú i
    }
}
faber format --locale ar — Arabic
بداية {
    كرر نطاق 010 كل 2 ثابت i {
        اعرض i
    }
}
faber format --locale hi — Hindi
आरंभ {
    दोहराओ सीमा 010 प्रति 2 स्थिर i {
        दिखाओ i
    }
}

While#

while loops while a condition holds.

reader locale
faber format --locale en — English reader surface
main {
    var int i  0
    while i ≺ 3 {
        i  i + 1
        print i
    }
}
faber format --locale la — canonical Faber
incipit {
    varia numerus i  0
    dum i ≺ 3 {
        i  i + 1
        nota i
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    แปร จำนวน i  0
    ขณะ i ≺ 3 {
        i  i + 1
        บันทึก i
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    变量 整数 i  0
     i ≺ 3 {
        i  i + 1
        显示 i
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    變值 整數 i  0
     i ≺ 3 {
        i  i + 1
        註記 i
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    biến số i  0
    trong_khi i ≺ 3 {
        i  i + 1
        ghi_chú i
    }
}
faber format --locale ar — Arabic
بداية {
    متغير عدد i  0
    طالما i ≺ 3 {
        i  i + 1
        اعرض i
    }
}
faber format --locale hi — Hindi
आरंभ {
    चर संख्या i  0
    जबतक i ≺ 3 {
        i  i + 1
        दिखाओ i
    }
}

Leaving early#

break breaks out; continue skips to the next iteration.

reader locale
faber format --locale en — English reader surface
main {
    const list<int> numeri  [1, 2, 3, 4, 5]
    for from numeri const n {
        if n  2 {
            continue
        }
        if n ≻ 3 {
            break
        }
        print n
    }
}
faber format --locale la — canonical Faber
incipit {
    fixum lista<numerus> numeri  [1, 2, 3, 4, 5]
    itera ex numeri fixum n {
        si n  2 {
            perge
        }
        si n ≻ 3 {
            rumpe
        }
        nota n
    }
}
faber format --locale th-TH — Thai
เริ่ม {
    คงที่ รายการ<จำนวน> numeri  [1, 2, 3, 4, 5]
    วน ออก numeri คงที่ n {
        ถ้า n  2 {
            ไปต่อ
        }
        ถ้า n ≻ 3 {
            หยุด
        }
        บันทึก n
    }
}
faber format --locale zh-Hans — Simplified Chinese
入口 {
    常量 列表<整数> numeri  [1, 2, 3, 4, 5]
    遍历 取自 numeri 常量 n {
        如果 n  2 {
            继续
        }
        如果 n ≻ 3 {
            中断
        }
        显示 n
    }
}
faber format --locale zh-Hant — Traditional Chinese
入口 {
    定值 列表<整數> numeri  [1, 2, 3, 4, 5]
    遍歷 取自 numeri 定值 n {
         n  2 {
            繼續
        }
         n ≻ 3 {
            中斷
        }
        註記 n
    }
}
faber format --locale vi — Vietnamese
bắt_đầu {
    hằng danh_sách<số> numeri  [1, 2, 3, 4, 5]
    lặp từ numeri hằng n {
        nếu n  2 {
            tiếp
        }
        nếu n ≻ 3 {
            dừng
        }
        ghi_chú n
    }
}
faber format --locale ar — Arabic
بداية {
    ثابت قائمة<عدد> numeri  [1, 2, 3, 4, 5]
    كرر من numeri ثابت n {
        إذا n  2 {
            تابع
        }
        إذا n ≻ 3 {
            اكسر
        }
        اعرض n
    }
}
faber format --locale hi — Hindi
आरंभ {
    स्थिर सूची<संख्या> numeri  [1, 2, 3, 4, 5]
    दोहराओ सेवन numeri स्थिर n {
        यदि n  2 {
            जारी
        }
        यदि n ≻ 3 {
            तोड़ो
        }
        दिखाओ n
    }
}

A loop can also carry its own error handler — see catch attaches to more than do.

Related: Control flow · Types and widths