Break and Continue: While Loops

Elizabeth Weiss cake240 at gmail.com
Sun Jun 26 15:08:42 EDT 2016


On Thursday, June 23, 2016 at 12:49:30 AM UTC-4, Lawrence D’Oliveiro wrote:
> On Thursday, June 23, 2016 at 4:17:23 PM UTC+12, Elizabeth Weiss wrote:
> > 
> > i=0
> > while 1==1:
> >    print(i)
> >    i=i+1
> >    if i>=5:
> >      print("Breaking")
> >      break
> > 
> > Why is Breaking going to be printed if i only goes up to 4? It does say if
> > i>=5?
> 
> Because you incremented i after printing its value, and before checking it.

Got it, Lawrence. Thanks so much for your help!!


More information about the Python-list mailing list