Ask Question
22 August, 17:37

Given the following code fragment, how many times does the loop body execute? int laps = 50; int myNum = 1; do { myNum = myNum + 2; laps = laps + 1; } while (laps < = 1);

+3
Answers (1)
  1. 22 August, 17:56
    0
    one

    Explanation:

    The loop is used to execute the part of code or statement again and again until the condition is not FALSE.

    There are three types of loop in programming.

    1. for loop

    2. while loop

    3. do-while loop

    Do-while has one special property which makes it different from other loops.

    The loop statement executes once if the condition of the loop is failed in the starting.

    In do-while, the statement executes first and then while checking the condition.

    let discuss the code:

    initially, laps=50, myNum=1

    then, the program executes the statement in the loop.

    so, myNum = 1 + 2=3.

    A value 3 is assign to the variable myNum.

    laps = 50 + 1=51.

    A value 3 is assigned to the laps variable.

    then while checking the condition (51 < = 1) which is FALSE.

    The program terminates the loop.

    Therefore, the answer is one.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given the following code fragment, how many times does the loop body execute? int laps = 50; int myNum = 1; do { myNum = myNum + 2; laps = ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers