Question

How many times will the body of the loop be executed? var Total = 1; for...

How many times will the body of the loop be executed?
var Total = 1;
for (intIndex = 1; intIndex < 7 ; intIndex += 2)
{
Total += intIndex;
}

Homework Answers

Answer #1

Answer of this question given below:-

var Total = 1;
for (intIndex = 1; intIndex < 7 ; intIndex += 2)
{
Total += intIndex;
}

For this code, The body of the loop be executed 3 times.

1st time :- intIndex =1

so, Total =Total + intIndex = 1+1 =2

2nd time :- intIndex =3       (intTndex=intIndex +2=1+2=3   and 3<7)

so, Total =Total + intIndex = 2+3 =5

3rd time :- intIndex =5    (intTndex=intIndex +2=3+2=5 and 5<7)

so, Total =Total + intIndex = 5+5 =10

Now,intIndex = intIndex+2=5+2 =7 then intIndex<7 condition not satisfy.

so,loop will be terminated.

Thus,The body of the loop be executed 3 times.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. How many times the loop below will be executed? What is the value of variable...
1. How many times the loop below will be executed? What is the value of variable counter after the loop? counter = 1 while counter < 7: counter+=2 print(counter) 2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”. 3. Complete the python below that asks user to enter the...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________ of these loops. 2. What will the following code fragment print?    for (i = 0; i < 4; i++)        cout << i + 1; cout << i; 3. What is the result in answer below? int int1=16; int int2=5; int answer=0; answer = int1 / int2 + (5 * 2);
What line prevents the loop from ending? int var = 0;     // 1 while ( var...
What line prevents the loop from ending? int var = 0;     // 1 while ( var < 10)     // 2 {      printf("%d\n", var);     //3 var--;    }
A streak isolation with 4 total section on a TSA plate how many times did you...
A streak isolation with 4 total section on a TSA plate how many times did you sterilize your inoculating loop
How many times does the following loop execute and why? for (unsigned m = 5; --m...
How many times does the following loop execute and why? for (unsigned m = 5; --m >= 0; ) printf(“hello\n”);
IN JAVA PLEASE How many times does the while loop execute for the given input values...
IN JAVA PLEASE How many times does the while loop execute for the given input values of -1 4 0 9 userNum=3;while (userNum>0){ //Do something //Get usernum firm input }
1) A 10-sided die is rolled infinitely many times. Let X be the number of rolls...
1) A 10-sided die is rolled infinitely many times. Let X be the number of rolls up to and including the first roll that comes up 2. What is Var(X)? Answer: 90.0 2) A 14-sided die is rolled infinitely many times. Let X be the sum of the first 75 rolls. What is Var(X)? Answer: 1218.75 3) A 17-sided die is rolled infinitely many times. Let X be the average of the first 61 die rolls. What is Var(X)? Answer:...
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a...
java beginner level NO ARRAYS in program Flip a coin (Assignment) How many times in a row can you flip a coin and gets heads? Use the random number generator to simulate the flipping of the coin. 0 means heads, 1 means tails. Start a loop, flip it, if heads, count it and keep flipping. If tails, stop the loop. Display the number of times in a row that heads came up. Once this is working, wrap a while loop...
Flip a coin 100 times and record the outcome (how many times heads, how many times...
Flip a coin 100 times and record the outcome (how many times heads, how many times tails), then create a table in Microsoft word and record your data.
About how many times bigger in radius is the Sun than the Earth? How many times...
About how many times bigger in radius is the Sun than the Earth? How many times bigger in mass?