Glossary
Boundary Cases
Specific input values that lie at the extremes or edges of valid ranges, used in testing to ensure a program handles unusual or limiting conditions correctly.
Example:
For a method that processes ages, testing with 0, 1, 17, 18, and a very large number would involve checking boundary cases.
Braces `{}`
Curly brackets used in Java to define the boundaries of code blocks, such as those associated with `if` statements, loops, or methods.
Example:
Forgetting braces around multiple lines of code after an if statement can lead to only the first line being conditionally executed.
Code Block
A group of programming statements enclosed within curly braces `{}` that are executed together as a single unit, typically associated with a control structure like an `if` statement or a loop.
Example:
The lines System.out.println("Access Granted!"); inside if (passwordCorrect) { ... } form a code block.
Condition
A boolean expression within an `if`, `else if`, or loop statement that evaluates to either true or false, determining whether a specific block of code should be executed.
Example:
In if (score >= 90), score >= 90 is the condition that decides if the 'A' grade code runs.
Decision Tree
A conceptual model used to visualize the flow of logic in conditional statements, where each `if` or `else if` represents a branch leading to a specific action.
Example:
Imagining your if-else if-else structure as a decision tree can help you map out all possible outcomes for different inputs.
Implicit `else`
A situation where the final `else` block in an `if-else if-else` structure is omitted, and the code following the structure acts as the default path if no preceding conditions were met.
Example:
If all if and else if branches in a method contain a return statement, a final return at the end of the method acts as an implicit else.
Indentation
The practice of using spaces or tabs to visually offset lines of code, improving readability and indicating the hierarchical structure of code blocks.
Example:
Proper indentation makes it easy to visually distinguish which statements belong to an if block versus an else block.
Multi-Way Selection (`if-else if-else` statements)
A control structure that allows a program to choose among multiple possible execution paths based on a series of conditions, where only one block of code will execute.
Example:
To determine a student's letter grade, you would use multi-way selection to check ranges like 90+ for 'A', 80-89 for 'B', and so on.
Order of Conditions
The sequence in which `if` and `else if` conditions are evaluated in a multi-way selection structure, where the first true condition's code block is executed and subsequent conditions are skipped.
Example:
When determining the largest divisor, checking for divisibility by 10 before 2 is crucial for the correct order of conditions.
Tracing Code
The manual process of stepping through a program's execution line by line with specific input values to predict its output and identify logical errors.
Example:
When debugging a complex conditional, tracing code with a pencil and paper helps you track variable changes and execution flow.
`else if` statement
A conditional statement that checks a new condition only if all preceding `if` and `else if` conditions within the same multi-way selection structure were false.
Example:
After checking if a number is divisible by 10, an else if statement might then check if it's divisible by 9, but only if it wasn't divisible by 10.
`else` statement
A control flow statement that executes a block of code if all preceding `if` and `else if` conditions within the same structure evaluate to false, serving as a default path.
Example:
If a user's input is not 'yes' or 'no', the else block might print an 'Invalid input' message.
`if` statement
The initial control flow statement in a conditional structure that executes a block of code only if its specified boolean condition evaluates to true.
Example:
An if statement might check if (temperature > 100) to decide whether to turn on the cooling system.
`return` statement
A statement that immediately terminates the execution of the current method and, optionally, sends a value back to the caller.
Example:
In a method calculating a discount, a return statement might send back the final discounted price as soon as it's computed.