33 lines
980 B
Plaintext
33 lines
980 B
Plaintext
& Lesson 3: Repeating things, simply
|
|
|
|
& Computers are good at repeating things:
|
|
|
|
repeat 4 {
|
|
forward! (100)
|
|
right! (0.25)
|
|
}
|
|
|
|
& let's take this line by line
|
|
& 5: repeat 4 {
|
|
& ^^^^^^ `repeat` is NOT a function, but a "special form"
|
|
& ^ this tells Ludus how many times to repeat a thing
|
|
& ^ this "curly brace" lets you group lines of code together
|
|
& we call this group a "block"
|
|
|
|
& 6: forward! (100)
|
|
& ^^ as a matter of style, we indent lines in a block
|
|
& ^^^^^^^^ we recognize this
|
|
|
|
& 7: right! (0.25)
|
|
& we recognize this, too
|
|
& but it has to be on its own line!
|
|
& (we could use a `;` instead of a newline)
|
|
|
|
& 8: }
|
|
& ^ We need to close the block we opened on line 5
|
|
& What happens if we forget it?
|
|
|
|
& What happens if you change the number of times it repeats?
|
|
& -- the distance the turtle goes forward?
|
|
& -- the amount we turn right?
|