Understanding and using selection questions and answers
Q1. How many basic ways are there to construct a selection construct?
A1. Two: If and Case
Q2. Write some pseudo-code that does the following. A single digit random number is assigned to a variable called Random. You have to enter a single digit and store it in a variable called Number. Then you have to test it. If it is the same as the random one, you display “Well done!” and if it isn’t you display “Sorry, not this time”.
A2.
Random = Get random number
Number = INPUT number from keyboard
IF (Number entered = Random) THEN
Display “Well done”
ELSE
Display “Sorry, not this time”
ENDIF
Q3. What is meant by a ‘nested IF statement’?
A3. An IF statement inside another IF statement.
Q4. Why is CASE usually preferred to lots of IF statements?
A4. It is easier to read and understand. Too many IF statements can make the code overly long and cumbersome.
Q5. Apart from selection, what are the other two programming constructions?
A5. Sequence and iteration.
Q6. What are the common symbols used in programming for 'not equal to'?
A6. <> and !=
Q7. What advice can you give someone to help them remember whether 'less than' is this symbol < or this symbol > ?
A7. The L in Less looks like and points in the same direction as the 'less than' symbol <.
Q8. Do some research. What is meant by the 'order of precedence'?
A8. This refers to whether what order you do a calcualtion when multiple symbols are used e.g. 4 + 6 * 2. In this case, multiplication comes before addition.
Q9. Do brackets have a higher or lower precedence than multiplication?
A9. Yes. Brackets have the highest precedence.
Q10. Does AND have a higher or lower precedence than OR?
A10. Yes, AND is done before OR. As a general rule with Boolean operators, expressions in brackets are always done first, then NOT comes next, then AND and finally OR expressions are evaluated.