hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Given the following code snippet in C++: Which of the following statements about the given do-while loop is correct?
    Question



    Given the following code snippet in C++:

    Which of the following statements about the given do-while loop is correct?

    A.

    The loop will never execute if the user enters -1 as the first input.

    B.

    The loop will execute at least once, regardless of the user input.

    C.

    The loop will execute exactly five times, regardless of the user input.

    D.

    The loop will terminate after exactly five iterations without checking user input.

    E.

    The loop will keep asking for input indefinitely if the user never enters -1.

    Correct option is B

    The correct answer is (b) The loop will execute at least once, regardless of the user input. Since this is a do-while loop, it will execute at least once before checking the condition, even if the user inputs -1 as the first value.
    Important Key Points:
    1. Do-While Loop Behavior: A do-while loop executes its body at least once before evaluating the condition, meaning the user will always be prompted for input once, regardless of the input value.
    2. The loop continues as long as number is not equal to -1 and count is less than 5. The loop may end after 5 inputs or earlier if -1 is entered.
    Knowledge Booster:
    · Option (a): Incorrect, because in a do-while loop, the body executes at least once, even if the user inputs -1 initially.
    · Option (c): Incorrect, because the loop may execute fewer than five times if the user enters -1 early.
    · Option (d): Incorrect, as the loop checks the conditions (number != -1 && count < 5) in each iteration and may terminate before five iterations.
    · Option (e): Incorrect, since the loop is bounded by both user input (-1) and the count < 5 condition. Therefore, it will not run indefinitely.

    Free Tests

    Free
    Must Attempt
    Video Solutions

    RBI Assistant Pre 2026 Full Mock Test -01

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Reasoning Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Quant Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    test-prime-package

    Access ‘IBPS SO IT Officer’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow