渲染zh-Hans

范围

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Selects numeric range iteration in an 遍历 loop.

Syntax: 遍历 范围 <range> <binding>

Category#

iteration

Examples#

radix/corpus/ab/ab.fab (canonical · keyword)#

Selects numeric range iteration in an 遍历 loop.

# =============================================================================
# 范围 — Selects numeric range iteration in an 遍历 loop.
# =============================================================================
#
# What this teaches:
#   • `遍历 范围` bounded range iteration — iterates over a numeric range with
#     an optional step
#   • Step syntax — the `per <step>` clause controls stride within the range
#
# Common mistakes:
#   • using the retired `范围`/`ubi` collection pipeline DSL; use ordinary collection methods and closures instead
#
# See also: 遍历, 取自, 借自, per, 范围 pipeline
# =============================================================================

# 范围 — bounded iteration step
#
# GRAMMAR:
#   iteraStmt :← '遍历' '范围' expr '‥' expr step? '常量' ident block
#
# EXPECTED OUTPUT:
#   Scalar stdout smoke (see body).
#

main {
    for range 0‥10 step 2 const i {
        print i
    }
}

Expected output:

0
2
4
6
8