Analyze the code below Then complete the table below to show

Analyze the code below. Then complete the table below to show the value of the variable \"i\" at the end of each iteration (defined by the comment in the code). Also, indicate how many total iterations of this while loop would occur by circling the last iteration number. int i = 0; while(i

Solution

iteration 1:

Before iteration value i = 0

0<2:

i = i+1

i = 1

In iteration 1 value i = 1

iteration 2:

1<2:

i = i+1

i = 2

In iteration 2 value i = 2

iteration 3:

Before iteration value i = 2

2<2: false

i = i+2

i = 4

i==4:

i=9

In iteration 3 value i = 9

iteration 4:

9<4: False

i = i+2

i = 11

In iteration 4 value i = 11

Since 11<10 is false while loop will end after iteration 4.

Hence iteration 4 is the last iteration

 Analyze the code below. Then complete the table below to show the value of the variable \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site