There are six commands in tintin for implementing different sorts of "loop" behavior:
- Foreach: For each item in the specified list, retrieve the value and execute some command(s).
- Forall: For all items in the specified list, execute some command. This command appears to be identical (except for the "goblin" syntax) to the #foreach command.
- Loop: Loop from and to specified indexes (a traditional for loop).
- While: Execute a set of command(s) until a specified condition is met.
- Parse: Iterate over a string and for each character, execute some command.
- Repeat: Execute some command a specified amount of times.
There are also two flow-control commands that can be used to alter the flow of the loops (though they appear to have identical behavior):
- Break: Stop executing the current loop and resume execution at the end of the loop's control structure.
- Continue: Stop executing the current loop and resume execution at the end of the loop's control structure.
I honestly can't think of a better name "looping through lists" in TinTin. The syntax is completely nonstandard and doesn't fit into the same context as anything else in TinTin++. I can never remember the syntax and have to look it up each time I write one.
From the foreach page of the official manual: > To loop through all items in a list (or a nested variable) using the foreach command use $<list>[%*].
The forall loop uses a special "goblin" syntax for referencing the value of the current item: "&0".
Example syntax:
#foreach {$mylist[%*]} {value} {
#showme {$value};
};
#forall {$mylist[%*]} {
#showme &0;
};
#loop {1} {5} {i} {
#showme {$mylist[$i]};
};
#var {i} {5};
#while {$i > 0} {
#showme {$mylist[$i]};
#math {cnt} {$cnt - 1};
};
#parse {a string of characters} {c} {#showme $c};
#10 #showme {repeat};