.while .done

Repeating generation sequences
The .while and .done statements allow sequences of source to be repeatedly processed by the assembler while one or more statements are modified. This allows short sequences of statements to by converted from a runtime loop into a statically built section of machine code. It also allows data tables to be built for runtime lookup (reducing runtime computational overheads).

The syntax of a loop is

```        .while <expr>
<block1>
.done```
The statements <block1> between the start and end of the loop are repeatedly processed while the expression <expr> evaluates to a non-zero value. The .break statement can be used to cause the processing of subsequent statements in <block1> to be stopped and the loop terminated.
```e.g.

squares_tbl

var1    .set    0
.while  var1 <= 10
.dw     var1 * var1
var1    .set    var1 + 1
.done```
this example generates a table of squares for all the integers between 0 and 10 inclusive

The following example does the same but nulls all odd entries

```squares_tbl

var1    .set    0
.while  var1 <= 10

.if     ((var1 * var1) & 1) == 0)
.dw     var1 * var1
.else
.dw     0
.endif

var1    .set    var1 + 1
.done```
The following example uses the .break statement to teminate the loop. It adds at least one 0 to the code generated and ensures that the location counter is always left at an even value
```        .while 1

.db     0

.if (\$ & 1) == 0
.break
.endif

.done```
.while / .done loops can be nested to any level.
```e.g.

var1    .set    1

.while  var1 <= 5

var2    .set    1

.while  var2 <= 5
.db     var1 * var2
var2    .set    var2+1
.done

var1    .set    var1+1
.done```
would produces the equivalent of
```        .db     1,  2,  3,  4,  5
.db     2,  4,  6,  8, 10
.db     3,  6,  9, 12, 15
.db     4,  8, 12, 16, 20
.db     5, 10, 15, 20, 25```