- What is the difference between a WHILE loop and a REPEAT loop in pseudocode?
- A WHILE...ENDWHILE loop is a pre-condition loop: the condition is tested before the statements run, so the loop may not happen at all. A REPEAT...UNTIL loop is a post-condition loop: the condition is tested after the statements run, so it is guaranteed to happen. A REPEAT...UNTIL loop ends when a condition is met, while a WHILE...ENDWHILE loop ends when its condition is not met.
- How do you write a FOR loop that counts in steps in pseudocode?
- Use FOR...NEXT. A loop such as FOR Count ← 2 TO 10 STEP 2 repeats a fixed number of times, counting from the start value to the end value. STEP sets how much the counter changes each time round, and the loop is closed with NEXT Count. A nested loop is a loop inside another loop, and the inner loop runs through all its repeats each time the outer loop goes round once.
- How do you find the largest and smallest numbers in a list using pseudocode?
- Set both the largest and the smallest variables to the first number input. It is the only number entered at that stage, so there is no comparison to be made. Then compare each later number with each variable in turn. Read the first number before the loop, so the loop runs one time fewer.
- What is the difference between ← and = in pseudocode?
- ← stores a value: the variable goes on the left and the value on the right, as in Count ← 0. = is a comparison, used in a condition such as UNTIL count = n. Writing Total = 5 instead of Total ← 5 is a common error, because it compares rather than stores.
- Why must every IF statement in pseudocode be closed with ENDIF?
- Failure to close IF statements with ENDIF is the most damaging mistake students make with selection. Each IF needs its own ENDIF in capitals, with THEN on a separate line and the lines inside indented. An action is credited only when it happens as a consequence of its own condition, so each IF holds only the actions for that condition.
- How do you find and correct a mistake in a given pseudocode algorithm?
- Identify the mistake itself, not just its line number, and then give the correction. Check the starting values, the direction of ←, the statement that changes a counter or total, and what the loop condition compares with. For example, total ← 10 is an incorrect initial value, and it should be total ← 0.