Han

Han Ferik

Home | Projects | AP CSA

AP CSA Unit 4: Using Objects

4.1:

- Iteration statements (loops) change the flow of control by repeating a set of statements zero or more times until a condition is met.

- Loops often have a loop control variable that is used in the Boolean condition, requiring the steps of initializing, testing, and changing the loop variable.

- In while loops, the Boolean expression is evaluated before each iteration, and the loop body executes as long as the condition is true, stopping when the condition is false.

- If the Boolean expression in a while loop evaluates to false initially, the loop body is not executed at all.

- Infinite loops occur when the Boolean expression always evaluates to true, causing the loop to never end.

- Off-by-one errors happen when the iteration statement loops one time too many or too few.

- Input-controlled loops often use a sentinel value (e.g., "bye" or -1) provided by the user to signal the loop to stop, though these are not on the AP CSA exam.

- Standard algorithms like computing a sum or average are commonly implemented with loops.

4.2:

- In a for loop, the initialization statement is only executed once before the evaluation of the test Boolean expression. The variable being initialized is referred to as a loop control variable.

- In each iteration of a for loop, the increment or decrement statement is executed after the entire loop body is executed and before the Boolean expression is evaluated again.

- A for loop can be rewritten into an equivalent while loop and vice versa.

4.3:

- Loops can be used to traverse or process a string.

- Standard algorithms using string traversals can determine if one or more substrings have a particular property.

- Loops can calculate the number of substrings that meet specific criteria.

- String traversals can create a new string with the characters reversed.

4.4:

- Nested iteration statements are iteration statements that appear in the body of another iteration statement.

- When a loop is nested inside another loop, the inner loop must complete all its iterations before the outer loop can continue.

4.5:

- A trace table can be used to keep track of the variables and their values throughout each iteration of the loop.

- We can determine the number of times a code segment will execute with a statement execution count. This is called run-time analysis.

- The number of times a loop executes can be calculated by largestValue - smallestValue + 1, where these are the largest and smallest values of the loop counter variable possible in the body of the loop.

- The number of times a nested for-loop runs is the number of times the outer loop runs times the number of times the inner loop runs.

Find me on the interwebs!

Github LinkedIn Instagram Facebook