Respuesta :

Answer:

The code segment was written in Python Programming Language;

The while loop equivalent is as follows:

i = 1

j = 1

while i < 6:

     while j < i + 1:

           print('*',end='')

           j = j + 1

     i = i + 1

     print()

Explanation:

(See attachment for proper format of the program)

In the given lines of code to while loop, the iterating variables i and j were initialised to i;

So, the equivalent program segment (in while loop) must also start by initialising both variables to 1;

i = 1

j = 1

The range of the outer iteration is, i = 1 to 6

The equivalent of this (using while loop) is

while ( i < 6)

Not to forget that variable i has been initialized to 1.

The range of the inner iteration is, j = 1 to i + 1;

The equivalent of this (using while loop) is

while ( j < i + 1)

Also, not to forget that variable j has been initialized to 1.

The two iteration is then followed by a print statement; print('*',end='')

After the print statement has been executed, the inner loop must be close (thus was done by the statement on line 6, j = j + 1)

As seen in the for loop statements, the outer loop was closed immediately after the inner loop;

The same is done in the while loop statement (on line 7)

The closure of the inner loop is followed by another print statement on line 7 (i = i + 1)

Both loops were followed by a print statement on line 8.

The output of both program is

*

*

*

*

*

Ver imagen MrRoyal
ACCESS MORE