Glossary
Computing a Sum (algorithm)
An algorithm that iterates through a sequence of numbers, accumulating their total value into a single sum variable.
Example:
To calculate the total cost of items in a shopping cart, you would use the computing a sum algorithm to add each item's price.
Computing an Average (algorithm)
An algorithm that calculates the arithmetic mean of a set of numbers by first summing them and then dividing by the count of numbers.
Example:
To find the average grade for a student, you would use the computing an average algorithm by summing all grades and dividing by the number of grades.
Condition (in loops)
A boolean expression that determines whether a loop's body should execute or terminate.
Example:
In while (score < 100), score < 100 is the condition that keeps the loop running.
Counter variable (in loops)
A variable used to track the number of iterations a loop has completed, often incremented or decremented in each pass.
Example:
In a loop designed to print 'Hello' five times, int i = 0; and i++ make i the counter variable.
Divisibility (algorithm)
An algorithm to determine if one integer is perfectly divisible by another without using the modulo operator, typically by repeatedly subtracting the divisor.
Example:
To check if 15 is divisible by 3 without %, you can repeatedly subtract 3 (15-3=12, 12-3=9, etc.) until you reach 0, demonstrating the divisibility algorithm.
Exception handling
A programming mechanism that allows a program to gracefully respond to runtime errors or unexpected events, preventing crashes.
Example:
When a user enters text instead of a number, exception handling can catch the error and prompt them to try again instead of crashing the program.
Exceptions
Runtime errors or abnormal events that disrupt the normal flow of a program's execution.
Example:
Trying to divide by zero or accessing an array index that doesn't exist are common examples of exceptions in Java.
Exiting the Loop
The process by which a loop terminates its execution, typically when its condition becomes false or a `break` or `return` statement is encountered.
Example:
The loop for a game might continue until the player's health reaches zero, at which point it performs exiting the loop.
Extracting Digits (algorithm)
An algorithm that isolates and processes individual digits of an integer, often using the modulo operator (`% 10`) and integer division (`/ 10`).
Example:
To print the digits of 123, the extracting digits algorithm would first get 3 (123 % 10), then 2 (12 % 10), and finally 1 (1 % 10).
Finding Maximum (algorithm)
An algorithm that iterates through a set of values to identify and return the largest value among them.
Example:
To discover the highest temperature recorded in a week, you would use the finding maximum algorithm to compare each day's temperature.
Finding Minimum (algorithm)
An algorithm that iterates through a set of values to identify and return the smallest value among them.
Example:
To determine the lowest score in a class, you would apply the finding minimum algorithm by comparing each score to a current minimum.
Flag (in loops)
A boolean variable used to control the flow of a loop, typically set to `true` to continue and `false` to terminate when a specific condition is met.
Example:
A boolean gameOver = false; variable can be used as a flag to keep a game loop running until gameOver is set to true.
Frequency of a Condition (algorithm)
An algorithm that counts how many times a specific condition is met within a sequence of data, typically using a loop and a counter.
Example:
To find how many even numbers are in a list, you'd use the frequency of a condition algorithm to iterate and increment a counter for each even number.
Infinite Loops
A loop that never terminates because its condition always evaluates to true, often due to a missing or incorrect update to the loop control variable.
Example:
If you forget to increment your counter in a while loop, you'll create an infinite loop that runs forever.
Iteration
The process of repeatedly executing a block of code until a specified condition is met.
Example:
When you want to print numbers from 1 to 10, you use iteration to repeat the printing action for each number.
Loop Body
The block of code enclosed within a loop that is executed during each iteration.
Example:
Inside a while loop, the statements that increment a counter or perform calculations are part of the loop body.
Loops
Control structures in programming that enable the execution of a block of code multiple times.
Example:
A loop can be used to process every item in a list, like calculating the total score from all student grades.
Sentinel (in loops)
A special value used to signal the end of input or a sequence, causing a loop to terminate.
Example:
When reading numbers until a user enters 000, 000 acts as the sentinel value.
Skipped Loops
A loop whose body is never executed because its initial condition evaluates to false.
Example:
If a while loop's condition is x > 10 but x starts at 5, the loop will be a skipped loop and never run.
`break` statement
A control flow statement that immediately terminates the innermost loop or `switch` statement it is contained within.
Example:
If you're searching for a specific item in a list using a loop, once found, you can use a break statement to stop searching immediately.
`catch` block
A section of code associated with a `try` block that specifies how to handle a particular type of exception if it occurs.
Example:
If a NumberFormatException occurs in the try block, the catch block for that exception will execute, perhaps printing an error message.
`continue` statement
A control flow statement that skips the rest of the current iteration of a loop and proceeds to the next iteration.
Example:
When processing a list of numbers, you might use a continue statement to skip over negative numbers and only process positive ones.
`finally` block
An optional section of code associated with a `try-catch` structure that always executes, regardless of whether an exception was thrown or caught.
Example:
After opening a file in a try block, the finally block is often used to ensure the file is closed, even if an error occurred during reading.
`try` block
A section of code enclosed within a `try` keyword where code that might throw an exception is placed.
Example:
When reading input from a file, the code that performs the file reading is placed inside a try block because it might throw an IOException.
`while` loop
A type of loop that repeatedly executes a block of code as long as its boolean condition remains true.
Example:
You might use a while loop to keep asking a user for input until they enter a valid number.