FREE AP CSA Control Structures Questions and Answers

0%

What will be the output of the following code?

Correct! Wrong!

The first if condition (x > 5) is true. The nested if condition (x < 20) is also true, so "A" is printed. The else block is skipped.

What will be the output of this code?

Correct! Wrong!

day = 3 matches the case 3, so "Wednesday" is printed. The break statement is missing, so execution falls through to the default case, printing "Invalid day". Output: "Wednesday Invalid day".

How many times will the following loop execute?

Correct! Wrong!

The loop starts with x = 5 and runs while x > 0. Iterations: x = 5, 4, 3, 2, 1. The loop executes 5 times before x = 0, at which point the condition x > 0 becomes false.

What is the output of this code?

Correct! Wrong!

The loop runs from i = 0 to i < 5. When i == 3, the break statement terminates the loop. Values 0, 1, 2 are printed before the loop exits.

What is the output of the following code?

Correct! Wrong!

The outer loop runs i = 0 and i = 1. For each value of i, the inner loop runs j = 0, 1, 2. The combinations printed are: 0,0 0,1 0,2 1,0 1,1 1,2.

Premium Tests $49/mo
FREE February-2025