While / else


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?


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

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


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


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


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


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)


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


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

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


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