Question

What kind of Loop Structure is this? Step Statement Notes iterations evals 8 iteration-8 9 evals-0 print( Boolean evaluation

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The loop structure provided in the code is the while loop. The while loop is a control structure, which is used to execute a set of commands continuously by means of a Boolean (true or false) or Flag (1 or 0) input condition.  

STEP STATEMENT NOTES a iteration evals

1

a=7

iteration = 0

evals = 0

The value of 'a' is initialized to be 7.

The value of 'iteration' is initialized to be 0.

The value of 'evals' is initialized to be 0.

7 0 0
2

print("Boolean evaluation #:", evals)

print("Iteration #:", iteration)

'Boolean evaluation #: 0' is displayed.

'Iteration #: 0' is displayed.

7 0 0
3 while True : The loop iterates as long as the value of 'a' holds true for 7. 7 0 0
4 a-=2 The value of 'a' is decremented by 2. 5 0 0
5 print("\nCurrent value of a:", a) 'Current value of a: 5' is displayed in the next line of the output. 5 0 0
6 iteration+=1 Increment the value of 'iteration' by 1. 5 1 0
7 print("Iteration #:", iteration) 'Iteration #: 1' is displayed. 5 1 0
8 evals+=1 Increment the value of 'evals' by 1. 5 1 1
9 print("Boolean evaluation #:", evals) 'Boolean evaluation #: 1' is displayed. 5 1 1
10

if a<=1 :

break

Checks if the value of a is less than or equal to 1. Since, it is not satisfying the condition, it doesn't enter the if loop and iterates again. 5 1 1
11 a-=2 The value of 'a' is decremented by 2. 3 1 1
12 print("\nCurrent value of a:", a) 'Current value of a: 3' is displayed in the next line of the output. 3 1 1
13 iteration+=1 Increment the value of 'iteration' by 1. 3 2 1
14 print("Iteration #:", iteration) 'Iteration #: 2' is displayed. 3 2 1
15 evals+=1 Increment the value of 'evals' by 1. 3 2 2
16 print("Boolean evaluation #:", evals) 'Boolean evaluation #: 2' is displayed. 3 2 2
17

if a<=1 :

break

Checks if the value of a is less than or equal to 1. Since, it is not satisfying the condition, it doesn't enter the if loop and iterates again. 3 2 2
18 a-=2 The value of 'a' is decremented by 2. 1 2 2
19 print("\nCurrent value of a:", a) 'Current value of a: 1' is displayed in the next line of the output. 1 2 2
20 iteration+=1 Increment the value of 'iteration' by 1. 1 3 2
21 print("Iteration #:", iteration) 'Iteration #: 3' is displayed. 1 3 2
22 evals+=1 Increment the value of 'evals' by 1. 1 3 3
23 print("Boolean evaluation #:", evals) 'Boolean evaluation #: 3' is displayed. 1 3 3
24

if a<=1 :

break

Checks if the value of a is less than or equal to 1. Since, it is satisfying the condition, it enters the if loop and breaks the while loop. 1 3 3
25

print("\nFinal value of a:", a)

print("\nTotal iterations :", iteration)

print("\nTotal boolean evaluations:", evals)

'Final value of a: 1' is displayed in the next line of the output.

'Total iterations : 3' is displayed in the next line of the output.

'Total boolean evaluations: 3' is displayedi n the next line of the output.  

1 3 3

A few print statements have been combined into a single step for ease of understanding. The above table depicts the execution steps, their explanations and the values of attributes declared of the code snippet provided in the question.

Add a comment
Know the answer?
Add Answer to:
What kind of Loop Structure is this? Step Statement Notes iterations evals 8 iteration-8 9 evals-...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What kind of Loop Structure is this? iterations evals Notes 16a-int (inputO) 17 b a Step Statemen...

    please fill the tables We were unable to transcribe this imageWhat kind of Loop Structure is this? iterations evals Notes 16a-int (inputO) 17 b a Step Statement 18 for x in range(a 3, a5, 2): 2 20 21 else: 23 24 print(b) 4 5 6 8 9 10 12 13 What kind of Loop Structure is this? Step Statement Notes iterations evals 18 19 20 21 iteration-0 evals-0 print("Boolean evaluation #:", evals) prin "Iteration #:", iteration! 23 evals1 24 while...

  • 3. A tor loop is useful when you know in advance the number of iterations to...

    3. A tor loop is useful when you know in advance the number of iterations to be executed. The tor loop consists of three parts each of which is separated by a semicolon (:). The first part is initialization of the variable for iteration, the second part is a test of the iteration variable and if this test fails, the loop is finished. The third part is a counter for the iteration variable. A block can be followed after the...

  • C++ Visual Studio 1. How many iterations are in the following "while" loop? int i =...

    C++ Visual Studio 1. How many iterations are in the following "while" loop? int i = 0; while(i < 20) { ++i; } 2. How many iterations are in the following "for" loop? for(int i = 5; i < 17; i = i + 2) { // Work } How many times will '+' be printed? int i = 0; while(true) { if(i == 5) { break; } cout << "+"; ++i; } 3. How many times will '+' be...

  • whats the answers What are the values of i for each iteration of: for (i =...

    whats the answers What are the values of i for each iteration of: for (i = 0; i < 6; ++i) { } 1 2 3 4 5 O 012345 0 0 1 2 3 4 5 6 1 2 3 4 5 6 For the following code, indicate how many times the loop body will execute for the following input values: 2 1 0? userNum = 3; while (userNum > 0) { // Do something // Get user Num...

  • this is true and false for C++ (1 point each) Circle T for true or F...

    this is true and false for C++ (1 point each) Circle T for true or F for false for the following questions. 1. T/F The Boolean expression b1 || b2 evaluates to true if either Boolean value (b1, b2) is true. T/F The code we write in C++ (e.g. code in file project1.cpp) is referred to as source code. 2. 3. T/F The statement float scores[3][3] creates 3 arrays, each containing 3 floating-point variables. T/F For loops work best when...

  • 1. True/False: An infinite loop occurs in a pre-test loop when a test condition can never...

    1. True/False: An infinite loop occurs in a pre-test loop when a test condition can never be met.      2. True/False: An infinite loop occurs in a post-test loop when a test condition can never be met. 3. True/False: The following statement will generate a loop with four iterations:                            for(count = 4; count > 0; count--) 4. True/False: The problem with a do...while loop is that the test condition cannot be a compound condition. 5. True/False: The following test...

  • Write a piece of Python code that meets the following requirements: Write a loop structure such...

    Write a piece of Python code that meets the following requirements: Write a loop structure such that: The range of control values is from 0 up to, but not including 11. The control variable is incremented by 1 for each iteration of the loop. For each iteration of the loop: Evaluate the control value When the control variable is equal to 1, 2, 3, 5, or 7, output a line of text that reads: "x is a prime number" where...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • How many Iterations will this while loop perform? int ico), j(10); cout << "i = "...

    How many Iterations will this while loop perform? int ico), j(10); cout << "i = " << i << endl; cout << "j = " << j << endl; while (i > j) { cout << "j-" « j << endl; j += 2; cout << "i = " << i << endl; } cout << "i = << i << endl; cout << "j = " << j << endl; 5 6 C 8 10 Infinite times Does the...

  • LAB5 #1. Method and loop Write a method integerPower(base, exponent) that returns the value of baseexponent...

    LAB5 #1. Method and loop Write a method integerPower(base, exponent) that returns the value of baseexponent (2 pts). For example, integerPower(3, 4) returns 81. Assume thatexponent is a positive nonzero integer, and base is an integer. Method integer should use for or while loop to control the calculation. Do not use any Math library methods. Incorporate this method into a program class and invoke this method with different combinations of input values at least 4 times. Please use printf() method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT