Ask Question
25 February, 16:33

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);

+1
Answers (1)
  1. 25 February, 16:57
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers