|
The following script plays nine sine waves, with frequencies of 200, 300, ..., 1000 Hz:
for i from 2 to 10
Create Sound as pure tone: "tone", 1, 0, 0.3, 44100, i * 100, 0.2, 0.01, 0.01
Play
Remove
endfor
The stop value of the for loop is evaluated on each turn. If the second expression is already less than the first expression to begin with, the statements between for and endfor are not executed even once.
The following script measures the number of trials it takes me to throw 12 with two dice:
throws = 0
repeat
eyes = randomInteger (1, 6) + randomInteger (1, 6)
throws = throws + 1
until eyes = 12
writeInfoLine: "It took me ", throws, " trials to throw 12 with two dice."
The statements in the repeat/until loop are executed at least once.
The following script forces the number x into the range [0; 2π):
while x < 0
x = x + 2 * pi
endwhile
while x >= 2 * pi
x = x - 2 * pi
endwhile
If the expression evaluates to zero or false to begin with, the statements between while and endwhile are not executed even once.
© ppgb 20140111