While & For Loops - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: While & For Loops (/thread-11090.html) |
While & For Loops - aditvaddi - Jun-22-2018 while True: for i in range(1,5): if i==3: continue print("{:>2}SAM".format(i))For this piece of code, why does it infinitely print out only 4SAM instead of infinitely doing: 1SAM 2SAM 3SAM 4SAM and so on.. RE: While & For Loops - Larz60+ - Jun-22-2018 indent your print, it's not part of the inner for loop the while will make this run forever, remove it RE: While & For Loops - volcano63 - Jun-22-2018 if i != 3: print(...)makes more sense. continue should be avoided - unless you check the condition close to the beginning of the cycle, and you want to avoid indenting large block of codefor <>: if i == 3: continue <long block of code saved from indentation> |