for loop

repeat a block of codes a fixed number of times

- The following will loop through 3 times
- The block of codes to be repeated must be enclosed in a pair of curly brackets
`{`

and`}`

- Output is as follows:
- You can also write the above using the javascript syntax:
- You can also increment by values other than 1. E.g. the following lists the even numbers:

```
for n from 1 to 3
{
echo "n = " + n
}
```

```
n = 1
n = 2
n = 3
```

```
for (n=1; n<=3; n++)
{
echo "n = " + n
}
```

Output is the same as above.

```
for (n=0; n<10; n+=2)
{
echo "n = " + n
}
```

Output

```
n = 0
n = 2
n = 4
n = 6
n = 8
```

## Comments (0)