How many times does for i = 1 to 5 run?
- i takes 1, 2, 3, 4, 5.
- Five times.
Answer 5
A-level Computer Science revision · Programming
Programs use three constructs. Sequence runs instructions in order. Selection (if, else if, switch/case) chooses a path. Iteration repeats: count-controlled (for loops) when the number of repeats is known; condition-controlled (while, do until) when it is not.
Watch out A while loop checks its condition before running and may run zero times; a do-until loop runs at least once.
How many times does for i = 1 to 5 run?
Answer 5
How many times is 'hello' printed by: for i = 0 to 8 step 2 / print('hello') / next i?
Which loop is best when you do not know how many times it will run?
What is the value of total after: total = 0; for i = 1 to 4: total = total + i?
A-level Computer Science Pro, OCR H446
£119 once
Price rises to £199 on 1 January. Save £80 by joining before then.
At least 12 months of access
No VAT is charged.