The WHILE directive is similar to REPEAT, but the loop continues as long as a given condition is true. The syntax is
WHILE expression
statements
ENDM
The expression must be a value that can be calculated at assembly time. Normally the expression uses relational operators, but it can be any expression that evaluates to zero (false) or nonzero (true). Usually, the condition changes during the evaluation of the macro so that the loop won't attempt to generate an infinite amount of code. However, you can use the EXITM directive to break out of the loop.
Summary: Loops are especially useful for generating lookup tables.
The following repeat block uses the WHILE directive to allocate variables initialized to calculated values. This is a common technique for generating lookup tables. Frequently it is faster to look up a value precalculated by the assembler at assembly time than to have the processor calculate the value at run time.
cubes LABEL BYTE ;; Name the data generated
root = 1 ;; Initialize root
cube = root * root * root ;; Calculate first cube
WHILE cube LE 32767 ;; Repeat until result too large
WORD cube ;; Allocate cube
root = root + 1 ;; Calculate next root and cube
cube = root * root * root
ENDM