|
|
|
< conditions |
Conditional Loops |
user functions > |
|
|
Sometimes you don't know in advance how many times to repeat a section of code. You can use a conditional loop to test an expression before each repeat. When the expression returns a zero, the loop stops. The loop counter $# tells you how many times the conditional loop has cycled. // bigger and bigger steps The system variables $x and $y refer to the x,y coordinates of the turtle. This program keeps drawing bigger steps until the x coordinate is greater than 100. You can also 'break out' of a do or while loop with the break command. This is usually used with an if statement inside the loop: do 200 A related command is continue. This stops processing the current repeated code section, and loops back to the start. // bigger and bigger odd-sized steps
|
|
< conditions |
user functions > |