Loop statements
in many practical problems have many repetitive operations that are regular, so some statements need to be executed repeatedly in the program. The
Z1h language provides the following types of loop processing statement
examples | loop types | description |
---|---|---|
for {…} | infinite loop | infinitely execute the logic in the code block, use the flow control statement to break the loop until |
(xxx) {…} | single conditional loop | When xxx (variable or expression) is true, loop |
for (var i = 0; i <10; i ++) {…} | classic loop body | for (single expression; conditional expression; end loop body) , If conditional expression is false, jump out of |
for (k, v in map) {…} | traverse map key-value pairs | traverse the contents of map, k is the key, v is the value |
for (ind, ele in arr) {…} | Traversing the array | traversing the contents of arr, ind is the index, ele is the element |
- In addition, there are methods for arrays such as
forEach / map / filter / filterMap / asyncMap
that can traverse the array *
** Please note , loop Z1h language code blocks can not be empty **
infinite loop
a = 0
for {
a ++
Print ( 'the Output:', a)
IF (a == 10)
BREAK
}
single conditions circulation
b = 15
for b {
b--
print ('Output:', b)
}
classic
loop"
for (var i = 0; i <5; i ++) {
print (
$ {i} The third power is $ (i ** 3) `)
}
## Traversal map
people = (
name: 'zwr',
age: 22,
)
for (k, v in people) {
print ( attribute $ {k}, {V}
value of $)
}
### traversing structure
REQ = new new (net_http.Request, {Method: 'the POST'})
for (K, V in REQ ) {
print (attribute $ (k), value $ (v)
)
}
### Traversing concurrent security map
m = new (sync.Map)
m.zh = 'Chinese'
m.en = 'English'
for (k, v in m) {
print ( abbreviated = $ {k}, {V} meaning
$ =)
}
## iterate
ARR = [. 8,. 9, 10]
for (IND, ELE in ARR) {
print ( The $ {ind + 1} element is: $ {ele}
)
}
"`