Loops
Loops are structures which allow one to run code a repeated number of times based on a condition. The currently supported looping structures in TLang are:
while
loops
while
loops
One can declare a while loop using the while
keyword followed by a
condition (an expression) as follows:
for
loops
One can declare a for loop using the for
keyword. A for loop consists
of 4 parts:
- A pre-run statement
- This is run once before the loop begins
- A condition
- Checked before starting the next iteration
- The body
- The code in-between the
{
and}
- The code in-between the
- A post-iteration statement
- Run at the end of each iteration
!!! info Currently it is required that your provide 1, 2 and 4 or else the program will not compile (see variations)
An example for loop is as follows: