3.2.2, 3.2.4, 3.2.5 - Selection and Boolean conditions (VB.NET)
Compare values, combine conditions and choose which VB.NET statements execute. The required code answer is written in VB.NET without Run; Python appears only in the optional demonstration.
Comparing values
A comparison produces a Boolean result that a program can use to make a decision.
| Operator | Meaning | Result when score is 10 |
|---|---|---|
score = 10 | Equal to | True |
score <> 10 | Not equal to | False |
score < 10 | Less than | False |
score > 10 | Greater than | False |
score <= 10 | Less than or equal to | True |
score >= 10 | Greater than or equal to | True |
= has a role determined by its context. score = 10 as a standalone statement assigns 10; If score = 10 Then compares the current value with 10. Native VB.NET inequality is <>, although supplied AQA pseudocode may use ≠.
Translate the wording carefully: “at least 10” includes 10, whereas “more than 10” does not. Trace the exact boundary and a value on each side. A check that works for 12 can still fail at 10.
Combining Boolean conditions
Boolean operators let one condition express more than one requirement.
And is true only when both operands are true. Or is true when at least one is true, including when both are true. Not reverses a Boolean value. For a club, entry might require age >= 12 And hasTicket; free entry might allow isVolunteer Or hasPass. Not banned is true when banned is false.
| A | B | A And B | A Or B | Not A |
|---|---|---|---|---|
| False | False | False | False | True |
| False | True | False | True | True |
| True | False | False | True | False |
| True | True | True | True | False |
For an inclusive range, write score >= 0 And score <= 10. Each side is a complete comparison; score >= 0 And <= 10 is incomplete native syntax. Values outside that range satisfy score < 0 Or score > 10. And would wrongly require a value to be below 0 and above 10 simultaneously.
Use brackets to show intended grouping: (isMember Or hasPass) And Not banned. With isMember = True, hasPass = False and banned = True, the bracketed expression is true but Not banned is false, so entry is false. The same Boolean expressions can control loops in later lessons.
Choosing which statements run
Selection changes the path through a program according to the value of a condition.
Continue this lesson.
You’re previewing NovaLearn without an account. Create a free account to read the rest.
Create free account