LearnFrenzy
Sign in Take a free test

Decision Making · Decision Making MCQ · Question 7

Nested if vs && – are they the same? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

Without any else, which is equivalent to if (a) { if (b) { work(); } }?

  • A if (a || b) work();
  • B if (a && b) work(); Correct
  • C if (a) work(); if (b) work();
  • D if (!a && !b) work();
Correct Answer: Option B

The inner block runs only when both conditions are true, and b is tested only when a is true – exactly the short-circuit behaviour of &&.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links