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...
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.
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users...
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users guess value to zero so we enter the loop guess = 0 while guess == computer_num guess = input ("Enter a guess (1-10)") print("Correct the number is "+str(computer_num)) How many times will “Correct the number is…” print when this code block is executed?.
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?
How many body tissue layers do arthropoda have and what are they? How many layers of...
How many body tissue layers do arthropoda have and what are they? How many layers of body tissues doe Echinodermata have and what are they?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT