Figure 3 shows a loop drawn as a flowchart. A programmer is going to write it as a high-level language program, using an IDE.
Complete Figure 4: identify how many times OK is output for each input value when Figure 3 runs.
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answer for 02.1Hide model answer for 02.1
Input 3
x = 3
OK (1)
x = 1, 1 < 0 is false
OK (2)
x = -1, -1 < 0 is true
stop
2 timesInput 10
x = 10
OK (1), x = 8
OK (2), x = 6
OK (3), x = 4
OK (4), x = 2
OK (5), x = 0, 0 < 0 is false
OK (6), x = -2, -2 < 0 is true
stop
6 timesHow the marks are earned
- One mark for each input value, up to 2.
- Input 3: OK is output 2 times.
- Input 10: OK is output 6 times.
Why it scores
Each pass outputs OK, then subtracts 2, then tests x. The loop only ends once x has gone below 0.
0 is not less than 0, so the loop goes round once more. That is why the count is 6 and not 5.
Revise Trace TablesIdentify and describe two different kinds of iteration that a high-level language offers.
See how you would score on Iteration (Loops)Show model answer for 02.2Hide model answer for 02.2
A FOR loop is count controlled. It repeats a set number of times.
A WHILE loop is condition controlled. It tests its condition before the code runs and repeats while that condition is true.
How the marks are earned
- Two marks for each loop, up to 4 in total. The marks are independent, and a description can score even if the loop is not named. Any two marks are credited for each loop.
- FOR loop, up to 2 marks from three creditable points: (a) the loop is named; (b) it is count controlled; (c) it repeats a set number of times.
- WHILE loop, up to 2 marks from three creditable points: (a) the loop is named; (b) it is condition controlled; (c) one mark for any one of these: it carries on as long as the condition holds, it stops once the condition is false, or the test is made before the body runs.
- DO UNTIL or REPEAT UNTIL loop, credited instead, up to 2 marks from three points: (a) the loop is named; (b) it is condition controlled; (c) one mark for any one of these: it carries on until the condition holds, it carries on while the condition is false, or the test is made after the body has run.
- Loops from other high-level languages are credited if suitable.
- If both a WHILE and a DO UNTIL are given, condition controlled can describe both, but it is credited once only unless the two are told apart in some other way.
- The description repeats infinitely earns nothing, because that is only true when the condition is never met.
- No credit where the description fits a different loop, for example saying that a while loop carries on until its condition becomes true.
Why it scores
Two marks from three creditable points: the name, the type and the rule for repeating. Only two are needed.
Two marks from three creditable points: the name, the type and the rule for repeating. Only two are needed.
Revise Iteration (Loops)Give the names of two programming constructs, other than iteration, that high-level languages use.
See how you would score on Selection (IF Statements)Show model answer for 02.3Hide model answer for 02.3
Sequence
Selection
How the marks are earned
- One mark for each construct, up to 2.
- Sequence. The form sequencing is credited.
- Selection. Branching is credited in its place.
- A bare example such as IF with no construct name earns nothing.
Why it scores
Sequence means instructions run one after another in the order they are written.
Selection means the program chooses which instructions to run, for example with an if statement.
Revise Selection (IF Statements)Identify and describe two IDE tools the programmer could use to create the program from Figure 3.
See how you would score on IDE FeaturesShow model answer for 02.4Hide model answer for 02.4
Tool 1: a code editor. It lets the programmer type in and change the program code, and fix errors.
Tool 2: a debugger. It finds errors in the program and shows the programmer where they are.
How the marks are earned
- For each tool, one mark for naming it and one mark for a matching description, up to 4. The description must add something beyond the tool name, and it must fit the tool named. If the tool name is wrong or missing, the description earns nothing. Other sensible names for a tool are accepted.
- Text or code editor: it lets program code be written, entered or changed, or errors fixed.
- Debugger, error reporting or diagnostics: it finds, identifies or checks for errors, shows where an error is or what it is, or suggests fixes.
- Run-time environment or output window: it lets the program be run, or shows the output of the program.
- Translator, compiler or interpreter: it converts the code to low-level or machine code, lets the program run, makes an executable file (compiler only) or stops at the first error (interpreter only). A translator and a compiler or interpreter are not both credited as two separate tools; compiler and interpreter as two separate tools are both credited with descriptions.
- Stepping: it runs the program one line at a time.
- Variable watch: it shows what the variables hold or how they change.
- Breakpoints: they stop the program at a chosen place.
- Pretty printing or keyword highlighting: it lets keywords or variables be coloured or identified.
- Keyword completion, autocomplete, autocorrect or syntax suggestions: they suggest or correct code; saying it happens once the first part is typed is not needed.
- GUI or GUI builder: it lets a user interface, such as buttons, be created.
- Other sensible IDE features are credited, for example line numbers, auto indent or collapsing blocks, if the description says a little more than the name.
- Features of a programming language, such as comments or casting, are not IDE tools and earn nothing.
- Sensible references to AI are credited.
- An editor, error diagnostics or debugger may be given a description that belongs to another feature in this list, for example the editor does pretty printing or the debugger does stepping.
Why it scores
Two marks: the tool, and a description that says what the tool is used for.
Two marks: the tool, and a matching description. The description fits the debugger and says more than its name.
Revise IDE Features