Structured Program Control Structures
Control structures are the backbone of any programming language. They dictate the flow of execution, allowing a program to make decisions, repeat actions, and respond to user input. In this…

Given the expression "!(6 <= 7)", what is the resulting Boolean value?
In an if‑else‑if chain, which block is executed when multiple conditions are true?
Which relational operator should be used to test whether a variable "score" is between 70 and 90 inclusive?
What will be printed by the following pseudo‑code? if (age >= 18) then write "Eligible" else write "Not eligible"
Which of the following best describes a single‑alternative selection statement?
Consider the nested selection code: if (balance > 5000) then set rate = 0.07 else if (balance >= 2500) then set rate = 0.05 else set rate = 0.03 If balance equals 2600, which rate is assigned?
Which logical operator correctly combines the conditions "age >= 18" and "age <= 65" to ensure age is within the working range?
In a loop structure, what term describes the statements that are repeatedly executed?
Which statement accurately reflects the behavior of a dual‑alternative (if‑else) selection when the condition evaluates to false?
Understanding Program Control Structures
Control structures are the backbone of any programming language. They dictate the flow of execution, allowing a program to make decisions, repeat actions, and respond to user input. In this course we will explore the most common structures—sequential, selection, and repetition—while focusing on the concepts that appeared in the quiz.
1. Repetition (Loop) Control Structures
When to Use a Loop
A loop repeats a block of code until a specified condition becomes false. The classic scenario is prompting a user for a password until the input is valid.
- Use a while or do‑while loop when the number of iterations is unknown.
- Use a for loop when you know exactly how many times the block should run.
Key Takeaways
- A loop repeats a block of code until a condition is met.
- It is the only control structure that can handle repeated attempts such as re‑asking for a password.
- Sequential structures run once, selection structures choose a path, but only loops handle repetition.
How to Remember
- Mnemonic: Loop = Last Only Once Problem solved – you keep looping until the problem (invalid password) is solved.
- Tip: Imagine a key that you keep turning until the door opens; each turn is an iteration of the loop.
2. Logical NOT and Boolean Expressions
Evaluating !(6 <= 7)
The expression 6 <= 7 evaluates to true because 6 is indeed less than or equal to 7. The logical NOT operator (!) flips the truth value, turning true into false.
Key Takeaways
- The relational expression
6 <= 7istrue. - The NOT operator (
!) inverts the result. - Therefore
!(6 <= 7)yieldsfalse.
How to Remember
- Mnemonic: “Less‑or‑equal gives true; NOT flips it to false.”
- Tip: Visualize the NOT operator as a light switch—if the light (truth) is on, flipping the switch turns it off (false).
3. Selection Statements: Single‑Alternative and Multi‑Alternative
Single‑Alternative (If) Statements
A single‑alternative selection statement executes a block only when a condition evaluates to true. If the condition is false, the program simply skips the block and continues.
Example
if (balance > 1000) {
applyDiscount();
}
When balance is greater than 1000, applyDiscount() runs; otherwise nothing happens.
Key Takeaways
- Executes a block only when the condition is true.
- There is no
elsebranch; the program proceeds without action if the condition fails.
If‑Else‑If Chains (Multi‑Alternative Selection)
In an if‑else‑if chain, the first condition that evaluates to true determines which block runs. Even if later conditions are also true, they are ignored because the chain stops at the first match.
Example
if (age < 13) {
category = "child";
} else if (age < 20) {
category = "teen";
} else if (age < 65) {
category = "adult";
} else {
category = "senior";
}
If age is 15, the second block (teen) runs, and the rest of the chain is skipped.
Key Takeaways
- Only the first true condition’s block is executed.
- Subsequent true conditions are ignored.
4. Relational Operators and Range Testing
Testing a Value Within a Range
To verify that a variable lies between two limits inclusive, combine the >= and <= operators with the logical AND (&&) operator.
if (score >= 70 && score <= 90) {
// score is within the desired range
}
This expression evaluates to true only when score is 70, 71 … 90.
Key Takeaways
- Use
>=and<=to include the boundary values. - Combine them with
&&so both conditions must be true.
How to Remember
- Mnemonic: “Between BOTH ends” → B for “>=” and “<=”, AND them together.
- Tip: Write the lower bound first, then the variable, then the upper bound, linking with
&&.
5. Combining Logical Conditions
Logical AND (&&)
The logical AND operator returns true only when both operands are true. It is essential for range checks such as ensuring an age falls within a working range.
if (age >= 18 && age <= 65) {
// eligible for employment
}
Using || (OR) would incorrectly allow ages outside the range, while ! (NOT) would invert the logic entirely.
Key Takeaways
&&requires both conditions to be true.- It is the correct operator for “and” relationships like age limits.
6. Practical Examples from the Quiz
6.1 Password Prompt Loop
Scenario: Keep asking the user for a password until it matches the stored value.
let input = "";
while (input !== correctPassword) {
input = prompt("Enter password:");
}
This demonstrates a repetition control structure.
6.2 Boolean NOT Example
let result = !(6 <= 7); // result is false
6.3 If‑Else‑If Chain
if (age < 13) {
console.log("Child");
} else if (age < 20) {
console.log("Teen");
} else if (age < 65) {
console.log("Adult");
} else {
console.log("Senior");
}
Only the first true block runs.
6.4 Nested Selection for Interest Rate
if (balance > 5000) {
rate = 0.07;
} else if (balance >= 2500) {
rate = 0.05;
} else {
rate = 0.03;
}
// With balance = 2600, rate becomes 0.05
6.5 Simple Eligibility Test
if (age >= 18) {
console.log("Eligible");
} else {
console.log("Not eligible");
}
This prints "Eligible" for any age 18 or older.
7. Summary and Best Practices
- Identify the problem type: repeat until → loop; choose one path → selection.
- Use relational operators (
>=,<=) to include boundaries. - Combine conditions with
&&for "and" logic, and with||for "or" logic. - Remember that an
if‑else‑ifchain stops at the first true condition. - Apply the NOT operator (
!) to invert a Boolean result.
Mastering these control structures will enable you to write clear, efficient, and maintainable code. Practice by converting everyday decision‑making scenarios into pseudo‑code, then implement them in your favorite programming language.
