Machine Problems: Advanced Loops

More Difficult Loops

If you have two students with different answers, you could ask them to reconcile their answers. In other words, to argue about the correct answer. These should have enough complexity to make that worthwhile.
1. m = 1
2. x = 17
3. print x
4. print m
5. m = m + 1
6. stop if m = 10
7. Go to instruction #3.


1. m = 0
2. x = 12
3. print x
4. print m
5. m = m + 1
6. stop if m = 10
7. if m = 5, x = 23
8. Go to #3.

1. m = 0
2. x = 10
3. x = x + 1
4. m = m + 2
5. stop if m = 10
6. if m = 4, x = 23
7. Go to #3.


1. n = 1
2. print n
3. n = n * 2
4. go to #2
5. Stop


1. i = 0
2. n = 0
3. n = n + i
4. i = i + 1
5. Go to #3 if i < 11
6. print n
7. Stop

Be the Machinemaster

My students could not easily make the transition to these problems -- they proved far more difficult than I expected. I think the problem was a lack of facility with variables. So I strongly recommend the Expressing Patterns problems as a prerequisite to these problems. Many of those problems were designed to teach the skills needed for the following machine problems.
Write commands to print out the squares of the numbers from 0 to 100

Add up the numbers from 0 to 100. Or if it is easier, write commands to make the machine calculate and print out the sum of the numbers from 0 to 100.

On March 1, Bob does 1 pushup. On March 2 he does 2 pushups, on March 3 he does 4 pushups. Every day in March he does twice as many pushups as he did the day before. Calculate how many pushups he does on March 31st. Or if it is easier, write commands to make the machine calculate and print out how many pushups he does on March 31st

Loop in a Loop

1. i = 0
2. j = 0
3. print j
4. j = j + 3
5. go to #3 if j < 10
6. i = i + 1
7. go to #2 if i < 5
8. Stop