1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ymorist [56]
3 years ago
9

Please convert this for loop into while loop

Computers and Technology
1 answer:
spayn [35]3 years ago
3 0

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

*

*

*

*

*

You might be interested in
The strength of the electromagnetic waves being radiated from an antenna is referred to as gain, which involves a measurement of
Mars2501 [29]

Answer:

Explanation:

dB - decibels - this is the ratio of power radiated to a reference value (signal strength)

i - isotropic - this represents a theoretical antenna that radiates an equal amount of power in all directions.

formula for antenna this:

GdBi=10*log^10(G)

5 0
3 years ago
You can add a new slide to a presentation by
jeka94
Clicking add slide to make more slides for your project
6 0
3 years ago
What’s the best way to figure out what wires what and goes where?
igor_vitrenko [27]
Try to untangle them, First!
Then the color of the wire must match the color hole it goes in (I’m guessing)
I’m not good with electronics so sorry.
6 0
4 years ago
who likes tom holland as spiderman and his web shooter tippets when he swings off buildings in new york city midtown, Forest Hil
S_A_V [24]

Answer:

YESSSS!!!!

Explanation:

5 0
3 years ago
Read 2 more answers
What are demographics? (with regards to marketing)
skad [1K]
Demographics are different groups of people you would want to appeal to. Ex. Women, Americans, Mexicans, Men, and Children.

And as always have a wonderful day user!
3 0
3 years ago
Other questions:
  • . True or False? a database breach always involves PII.<br><br> A.true<br><br> B.false
    5·1 answer
  • Software that interprets commands from the keyboard and mouse is also known as the A.hard drive.B.operating system.C.desktop or
    7·2 answers
  • Please help!
    10·1 answer
  • Which major and minor keys have no sharps or flats apex?
    5·2 answers
  • You would like to know how many cells contain data. Which function should you use?
    11·1 answer
  • Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
    13·1 answer
  • Types of computer that we use in our daily life​
    13·2 answers
  • Complete the sentence about entering and editing data in a cell in a spreadsheet.
    13·1 answer
  • Oliver is working for a team that uses object-oriented concepts to design software. Which language would they use to develop thi
    10·1 answer
  • Write two statements that each use malloc to allocate an int location for each pointer. Sample output for given program:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!