Exam code: 9618
1/410Still learning
Know0
Was this flashcard helpful?
What does an IF statement allow you to do?
It allows you to execute a set of instructions if a condition is true.
What is the pseudocode syntax for an IF statement without an ELSE clause?
IF <condition> THEN, then the statement or statements, closed with ENDIF.
What is the pseudocode syntax for an IF statement with an ELSE clause?
IF <condition> THEN, the statements, then ELSE, the alternative statements, closed with ENDIF.
Which keyword closes every IF statement in pseudocode?
ENDIF
True or False?
An IF statement must always have an ELSE clause.
False.
An IF statement can be written with or without an ELSE clause.
Define nested if statement.
A nested IF statement is an IF statement within another IF statement.
What does 'nested' mean?
Stored inside the other.
In the champion example, what is output when Player2Score beats both Player1Score and HighScore?
Player2, " is champion and highest scorer"
In the champion example, what is output when Player2Score beats Player1Score but not HighScore?
Player2, " is the new champion"
Selection is used for validation, calculation and making sense of a user's .
Selection is used for validation, calculation and making sense of a user's choices.
When is a CASE statement useful?
When comparing multiple values of the same variable. It can mean less code than a chain of IF statements.
Why are IF statements generally used more often than CASE statements?
IF statements are more flexible.
True or False?
A CASE statement can compare values of several different variables.
False.
A CASE statement is only useful when comparing multiple values of the same variable.
What is the pseudocode syntax for a CASE statement?
CASE OF <identifier>, then a <value> : <statement> line for each case, closed with ENDCASE.
Which keyword closes a CASE statement?
ENDCASE
What is the purpose of the OTHERWISE clause?
It handles any value that is not matched by the listed cases.
An OTHERWISE clause can be the clause of a CASE statement.
An OTHERWISE clause can be the last clause of a CASE statement.
In the direction example, what is output if the user enters "E"?
"You are heading East"
In the direction example, what is output if the user enters "X"?
"Invalid direction entered", because the OTHERWISE clause catches any unmatched value.
Define count-controlled loop.
A count-controlled loop is when code is repeated a fixed number of times, for example using a FOR loop.
What is the pseudocode syntax for a FOR loop?
FOR <identifier> ← <value1> TO <value2>, then the statements, closed with NEXT <identifier>.
How do you add a step value to a FOR loop?
Add STEP <increment> after TO <value2>.
What must the increment in a FOR loop evaluate to?
An expression that evaluates to an integer.
In a FOR loop, the identifier is updated by the value on each iteration.
In a FOR loop, the identifier is updated by the increment value on each iteration.
When does a FOR loop stop?
When the identifier passes value2.
True or False?
The increment in a FOR loop must be positive.
False.
The increment can be positive or negative, depending on the direction you want the loop to count.
Two FOR loops are nested, each running from 1 to 3.
How many lines of output are produced?
Nine, because the inner loop runs three times for each of the three passes of the outer loop.
In the nested FOR example that outputs i * j, what is printed on the first line?
1 x 1 = 1
When should you use a count-controlled loop?
When you know in advance how many times you want the loop to run.
Define condition-controlled loop.
A condition-controlled loop is when code is repeated until a condition is met.
Name the two types of condition-controlled loop.
Post-condition (REPEAT) and pre-condition (WHILE).
What must the condition of a condition-controlled loop evaluate to?
An expression that evaluates to a Boolean, that is True or False.
What is the pseudocode syntax for a post-condition loop?
REPEAT, then the statements, closed with UNTIL <condition>.
What is the pseudocode syntax for a pre-condition loop?
WHILE <condition> DO, then the statements, closed with ENDWHILE.
How many times does a post-condition loop run as a minimum?
At least once, because the condition is tested after the statements have been executed.
When does a REPEAT loop stop?
Only once the condition evaluates to True.
True or False?
A REPEAT loop stops when its condition evaluates to False.
False.
A REPEAT loop stops once the condition evaluates to True.
When does a WHILE loop end?
When the condition evaluates to False.
When should you use a pre-condition WHILE loop?
When you want to check a condition before running the loop. It may run 0 or more times.
When should you use a post-condition REPEAT loop?
When you want the loop to run at least once, and then stop when a condition becomes true.
In the nested WHILE example, the outer loop runs times, once for each username.
In the nested WHILE example, the outer loop runs 3 times, once for each username.
By signing up you agree to our Terms and Privacy Policy