[Tutor] For loop with break & else

Manprit Singh manpritsinghece at gmail.com
Thu Oct 22 03:21:42 EDT 2020


Dear sir ,

consider a problem where there is a for loop with break and else:

for i in range(2, y):
    if cond:
        break
else :
    do_something( )

in this pattern, let 's say if  y is a user input. and at a particular time
the user inputs the value of y equals to 2 . At that time,  the "else"
part  will be executed
or not ?

Regards
Manprit singh


More information about the Tutor mailing list