While / else


#1

i had few doubts regarding this program. we know that when 'break' is added to loop we can exist from the loom. and in this program we have given count += 1 ie we have to increase count(ie count = 0, for second it will be 1) hear i have a doubt that when we pass 'break' statement de we increase count by 1 or not.

can any one clear my doubt?


#2

if break is reached, the loops simply breaks (ends)

so once a break is reached, count will no longer increase


#3

could u tell me why we get 4,2,5 in out put.


#4

because on line 9 you print num, which is the random generated at line 8


#5

ok. system will take any random numbers from 1 to 6. is it wright.


#6

yea, randint() will generate a random number, and you printed this random number which is why you get 4,2,5 in the output

If you run it again, you will get different numbers (or the same, but that change is very small)


#7

i have doubt that in while loop else: works only while loop is false. is it right.


#8

if you have a while/else, else will only run the loops condition becomes false

If the look break's, else won't run


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.