nerdexam
iSQI

CTAL-TTA_001 · Question #29

What is the number of nested levels for the code fragment? 2 credits [K3]

The correct answer is C. 2. Option C (2) is correct because the code fragment contains two control structures (such as loops or conditionals) where one is entirely embedded inside the other - the outermost structure counts as level 1, and the structure nested within it counts as level 2. Option A (0) is…

Analytical Techniques

Question

What is the number of nested levels for the code fragment? 2 credits [K3]

Options

  • A0
  • B1
  • C2
  • D3

How the community answered

(31 responses)
  • A
    10% (3)
  • B
    3% (1)
  • C
    84% (26)
  • D
    3% (1)

Explanation

Option C (2) is correct because the code fragment contains two control structures (such as loops or conditionals) where one is entirely embedded inside the other - the outermost structure counts as level 1, and the structure nested within it counts as level 2.

Option A (0) is wrong because zero nesting means purely sequential code with no control structures at all, which clearly isn't the case here. Option B (1) is wrong because that would require only a single control structure with nothing nested inside it. Option D (3) would require a third structure embedded within the second nested structure, which exceeds what's present in the fragment.

Memory tip: Count the number of times you "step inward" past a new control structure (loop, if, switch, etc.) from the outermost level - each step inward adds one nesting level. Alternatively, picture matching brackets or indentation layers: two layers deep = 2 nested levels.

Topics

#nesting depth#code complexity#code metrics#static analysis

Community Discussion

No community discussion yet for this question.

Full CTAL-TTA_001 Practice