AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Easyconditionals

~45s

Which branch fires

What value of grade is printed?

Integer marks, grade
Set marks = 72
If marks >= 90 Then
    Set grade = 1
Else If marks >= 75 Then
    Set grade = 2
Else If marks >= 60 Then
    Set grade = 3
Else
    Set grade = 4
End If
Print grade
Show the answer and the worked solution

Correct answer: C.

3

Worked solution

  1. marks >= 90 is false, since 72 is below 90.
  2. marks >= 75 is false, since 72 is below 75.
  3. marks >= 60 is true, so grade = 3 and the rest of the chain is skipped.

Answer: 3.

The idea

An if / else-if ladder is exclusive: the first true condition wins and no later test is even evaluated. Reading the conditions out of order is the usual source of error.

Shortcut. Place 72 in its band: it sits in 60–74, the third band from the top, so grade 3 is printed.

Common trap. 4 tempts a candidate who sees 72 fail both upper tests and jumps straight to the final Else, overlooking the marks >= 60 rung that catches it first.

Which branch fires — Pseudocode Aptitude Question

Which branch fires: What value of grade is printed? Answer and worked solution on CodeKairo.

Question

What value of grade is printed?

Integer marks, grade
Set marks = 72
If marks >= 90 Then
    Set grade = 1
Else If marks >= 75 Then
    Set grade = 2
Else If marks >= 60 Then
    Set grade = 3
Else
    Set grade = 4
End If
Print grade

Options

  1. 1
  2. 2
  3. 3
  4. 4
Show the answer and the worked solution

Correct answer: C. 3

Worked solution

  1. marks >= 90 is false, since 72 is below 90.
  2. marks >= 75 is false, since 72 is below 75.
  3. marks >= 60 is true, so grade = 3 and the rest of the chain is skipped.

Answer: 3.

The idea

An if / else-if ladder is exclusive: the first true condition wins and no later test is even evaluated. Reading the conditions out of order is the usual source of error.

Shortcut. Place 72 in its band: it sits in 60–74, the third band from the top, so grade 3 is printed.

Common trap. 4 tempts a candidate who sees 72 fail both upper tests and jumps straight to the final Else, overlooking the marks >= 60 rung that catches it first.

All Pseudocode questions · placement mock tests