Glossary
Code Tracing
The systematic process of manually executing code line by line, meticulously tracking the values of variables and the program's output to understand its behavior.
Example:
When you're trying to figure out why your game character isn't moving correctly, you might code trace the movement logic to see how x and y coordinates change with each frame.
Condition (For Loop)
The second part of a for loop's header, evaluated before each iteration; if true, the loop body executes, otherwise the loop terminates.
Example:
For for (int i = 0; i < 10; i++), the condition i < 10 determines if the loop continues, stopping once i reaches 10.
Debugging
The process of identifying, analyzing, and removing errors or 'bugs' from computer programs.
Example:
When your program crashes unexpectedly, you'll need to start debugging by tracing the code to find the source of the problem.
Flow of Control
The order in which individual statements, instructions, or function calls are executed or evaluated in a program.
Example:
Understanding the flow of control is crucial when tracing a program with if-else statements and loops, as it dictates which code blocks run.
For Loop
A control flow statement that allows code to be executed repeatedly a specific number of times, typically defined by an initialization, a condition, and an update expression.
Example:
To print numbers from 1 to 10, you'd use a for loop like for (int i = 1; i <= 10; i++).
Infinite Loop
A loop that continues to execute indefinitely because its termination condition is never met, often due to a logical error or missing update statement.
Example:
If you forget to increment i in a while (i < 5) loop, you'll create an infinite loop that prints forever.
Initialization (For Loop)
The first part of a for loop's header, executed only once at the very beginning, typically used to declare and set an initial value for the loop control variable.
Example:
In for (int count = 0; count < 5; count++), int count = 0 is the initialization that sets up the loop counter.
Inner Loop
In a nested loop structure, the loop that is contained within another loop; it completes all its iterations for each single iteration of the outer loop.
Example:
When printing a 5x5 square of asterisks, the loop responsible for printing each row's asterisks is the inner loop.
Nested For Loops
A programming construct where one for loop is placed inside another, allowing for iteration over multiple dimensions or combinations.
Example:
Creating a grid or a multiplication table often involves nested for loops, with an outer loop for rows and an inner loop for columns.
Off-by-one Error
A common logical error in programming where a loop iterates one too many or one too few times, often caused by incorrect boundary conditions (e.g., using `<` instead of `<=`).
Example:
If you want to print numbers 1 through 5 but your loop prints 1 through 4, you likely have an off-by-one error in your loop condition.
Outer Loop
In a nested loop structure, the loop that contains one or more other loops; it controls the overall number of times the inner loop(s) will execute their full cycle.
Example:
To create a triangular pattern, the outer loop might control the number of rows, while the inner loop prints characters for each row.
Tracing Table
A structured table used during code tracing to organize and record the state of variables, iteration numbers, and program output at each step of execution.
Example:
To predict the output of a complex loop, an AP CSA student might create a tracing table with columns for i, j, and sum to track their values.
Update (For Loop)
The third part of a for loop's header, executed after each iteration of the loop body, typically used to modify the loop control variable.
Example:
In for (int k = 1; k <= 7; k++), k++ is the update that increments k after each run, moving towards the loop's end.
While Loop
A control flow statement that repeatedly executes a block of code as long as a specified boolean condition remains true.
Example:
A game might use a while loop like while (player.isAlive()) to keep the game running until the player's health drops to zero.