Ask Question
18 October, 05:34

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. 18 October, 09:07
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers