Repeats the sequence of commands between this REPEAT command and the corresponding END command as many times as specified by the input number. The input number may be a variable as shown in the example. The repeat command sets the number of its repetitions before beginning to execute any of the commands in its scope and doesn't allow it to be changed during the loop. Whatever value the inputNumber has when the loop begins is the number of repetitions that will occur, even if the value of inputNumber is explicitly changed within the loop. For example, this piece of code, COPY 10 number REPEAT number PRINT number SUBTRACT number 1 number END will print out 10 values of number from 10 down to 1 even though number is changing within the loop. The only exception to this is if a BREAK command forces the loop to exit. |
What is the probability of getting exactly two heads when tossing three coins? NAME heads tails COPY 10000 howManyTimes COPY 0 successCount REPEAT howManyTimes SAMPLE 3 (heads tails) toss ' simulate tossing 3 coins COUNT toss = heads headCount IF headCount = 2 ADD 1 successCount successCount END END DIVIDE successCount howManyTimes probability PRINT probability Two runs of the above program produced the following results: probability: (0.3767) probability: (0.3699)
|