Break and Continue: While Loops

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Thu Jun 23 00:49:17 EDT 2016


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.


More information about the Python-list mailing list