Paper II: Selection and Iteration Flashcards
What are selection functions for?
To make a decision between two or more options.
What three statements represent selection in pseudocode?
IF
ELSE
ELIF or ELSEIF
How do you use ELSE IF?
You embed the IF construct under the ELSE statement.
How is selection represented in flowcharts?
With a rhombus shape that has the two options: YES and NO.
What is iteration for?
Iteration i the process of repeating a set of instructions for a set amount of times or until the desired outcome is reached.
What is count controlled iteration?
When the number of iterations is known before loop is started.
What programming structure is used?
FOR loop e.g. FOR turns FROM 0 TO 3 DO SEND turns TO DISPLAY END FOR
This will output 0, 1, 2 and 3
How do you structure a FOR loop with a step?
FOR index FROM 2 TO 10 STEP 2 DO
SEND index TO DISPLAY
END FOR
This will output 2, 4, 6, 8 and 10
FOR EACH structure?
SET scores TO [9, 6, 7, 3, 9]
FOR EACH score FROM scores DO
SEND score TO DISPLAY
END FOR
This will output 9, 6, 7, 3 and 9
What is condition controlled iteration?
Used when the number of loops is determined by a condition.
What programming structure is used?
SET number TO 0
WHILE number <> 3 DO
RECEIVE number FROM (INT)KEYBOARD
END WHILE
REPEAT … UNTIL loops?
They continue until a condition becomes true.
e.g.
REPEAT
RECIEVE number FROM (INT)KEYBOARD
UNTIL number = 3
It will continue looping until 3 is entered
REPEAT … TIMES?
This loop will be repeated the number of times indicated.
e.g.
REPEAT 10 TIMES
RECEIVE score FROM (INT)KEYBOARD
END REPEAT