|
|
|
< simple loops |
Conditions |
conditional loops > |
|
|
In Tymless, as in most programming languages, you can place conditions upon a section of code, so that the code is only run if the conditions apply. To illustrate this let's draw a chess-board. This is a grid with alternating black and white squares. There are many ways of doing this in Tymless, and here is one of them: // program 4: a chessboard We are using the brightness control to alternate between black and white squares. The if statement tests the value of the expression that follows it. If the result is zero the conditional statements are not executed. Otherwise they are. I have put the condition in brackets just to make it clearer, but this is not necessary. The eq operator returns a 0 or 1 depending on whether the two sides are equal. In this case we could simplify the if statement to:
athough in fact it would be simpler to drop it altogether and say:
the not function returns a zero; unless the argument is zero, in which case it returns 1. Tymless provides a number of operators for testing conditions, such as ne (not equal), lt (less than), and, or etc.
|
|
< simple loops |
conditional loops > |