CCEA A-Level Software Systems Development CL4
Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures
Exception Handling and Managing Input and Output
Testing an Object Oriented Application
Graphical User Interface Objects and Events
Multiple Forms and Linking to Files
Designing, Testing and Evaluating an Event Driven Application
Reasons for Systems Development and Systems Methodologies
Managing Projects
Testing Strategies
Database Concepts and Entity Relationship Modelling
Normalisation and Structured Query Language
Project Management and the Systems Approach in Practice
Defining Requirements and Documenting the Design
Building a Desktop Solution with a Database
Testing and Evaluating the Solution
Program Control Structures
Breaking out of loops and avoiding infinite loops
- 3 things to know
- AS Unit 1
Overview
How a flag-controlled search loop works, infinite loop and loop guard.
What you need to know
Answer each one before you reveal it.
What does break do inside a loop?
What does continue do inside a loop?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What does break do inside a loop?
Model answer
A break abandons the loop immediately, so no further passes occur and execution continues at the first statement after the loop.
- 2
What does continue do inside a loop?
Model answer
A continue abandons the rest of the current pass only, so execution jumps to the loop update and condition and the loop carries on.
- 3
for (int i = 1; i <= 5; i++) { if (i == 3) { break; } System.out.print(i + " "); } — what does this fragment print?
Model answer
The loop prints 1 and then 2, and on the third pass the break leaves the loop before the printing statement, so the output is 1 2.
- 4
for (int i = 1; i <= 5; i++) { if (i == 3) { continue; } System.out.print(i + " "); } — what does this fragment print?
Model answer
Only the pass with the counter at 3 is cut short, and the remaining passes print as normal, so the output is 1 2 4 5.
- 5
Why do some programmers avoid break, and what is the structured alternative?
Model answer
A break gives the loop a second exit point, which makes the flow harder to follow; the structured alternative is a boolean flag set inside the loop and tested in the loop condition.
- 6
Describe how a flag-controlled search loop works.
Model answer
A boolean flag starts false and the loop continues while the flag is false and items remain; when the wanted item is met the flag is set to true, which ends the loop at the next test without a break.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Program Control Structures, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.