Question

BIS115. How many different repetition structures does Python support? What are the major differences between them?

BIS115.

How many different repetition structures does Python support?

What are the major differences between them?

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

python supports 2 repetition structures.

repetition structures in the sense with in the block of code executed repeatedly.

1)condition controlled

2)count controlled

1)condition controlled in the sense while loop.

based on the condition while loop iterates.the while loop iterates until the condition must be satisfied.

ex:

i=0

while( i != 1):

print("hi")

#output:first here i initialize with 0 so later go to next statement while(0!=1):

so the condition is correct so enter into loop and print("hi") again go back to while(0!=1):

condition satisfied so again print "hi" so again go its prints infinity time there is no end.

so we must give condition when the while loop stops.if we want stop the loop we must add condition

satisfied.

ex: to stop the repetition

i=0

while( i != 1):

print("hi")

i=1

so we add one statement so first i=0 so enter into loop and print "hi" later statement i=1.

so i changes 0 to 1. so present i=1

while(1!=1):

its false so terminate the loop only output is "hi"

2)count controlled in the sense its based on the count.example for loop we give particular count the loop run.

ex:

for i in range(1,10,1):

print(i)

output:

1 2 3 4 5 6 7 8 9

for(start,end,increment):

for take 3 parameters first one where we start second where we end third one which kind of skip we need

for starting with 1 and ending number is 10 increment 1

first print 1

later increment 1

print 2

later increment 1

so print 2+1=3

so print 3

until we reach the 10.

when we i reaches 10 the loop terminates.

this is the for loop.

it wan count controlled

major difference is condition controlled terminates based on the condition

count controlled terminates based on the count.

#if you have any doubts comment below.if you like give thumsup...

Add a comment
Know the answer?
Add Answer to:
BIS115. How many different repetition structures does Python support? What are the major differences between them?
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
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