Skip to content
Sharp

Core Java · interview question

Which loop structure would you use to ensure a piece of code runs at least once to add taxes to a cart total?

Multiple choiceMediumchapter-1-curatedpremiumcore-javaloops-and-iteration
Choose one answer
Answer and explanation

Correct answer

A. Do-while loop

Why

A 'do-while loop' guarantees that the loop body executes at least once before checking the condition, making it suitable for scenarios where the code must run at least once.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →