Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
On Thursday, June 23, 2016 at 12:17:23 AM UTC-4, Elizabeth Weiss wrote: > CODE #1: > > i=0 > while 1==1: >print(i) >i=i+1 >if i>=5: > print("Breaking") > break > > -- > I understand that i=0 and i will only be printed if 1=1 > The results of this is > 0 > 1 > 2 > 3 > 4 >

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
On Thursday, June 23, 2016 at 1:20:37 AM UTC-4, DFS wrote: > On 6/23/2016 12:17 AM, Elizabeth Weiss wrote: > > > CODE #1: > > > > i=0 > > while 1==1: > >print(i) > >i=i+1 > >if i>=5: > > print("Breaking") > > break > > > > -- > > I understand that i=0 and i will only be p

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
On Thursday, June 23, 2016 at 1:06:09 AM UTC-4, Rustom Mody wrote: > On Thursday, June 23, 2016 at 9:47:23 AM UTC+5:30, Elizabeth Weiss wrote: > > CODE #1: > > > > i=0 > > while 1==1: > >print(i) > >i=i+1 > >if i>=5: > > print("Breaking") > > break > > > > -- > > I under

Re: Break and Continue: While Loops

2016-06-26 Thread Elizabeth Weiss
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

Re: Break and Continue: While Loops

2016-06-26 Thread Steven D'Aprano
On Sun, 26 Jun 2016 05:32 pm, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: >> I seem to recall that Java originally insisted that only booleans >> (excluding even Booleans, which are a different thing because of >> course they are) could be chec

Re: Break and Continue: While Loops

2016-06-26 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 11:58:01 PM UTC+12, Jon Ribbens wrote: > I seem to recall that Java originally insisted that only booleans > (excluding even Booleans, which are a different thing because of > course they are) could be checked for truth and it was one of > Java's significant warts. Ja

Re: Break and Continue: While Loops

2016-06-24 Thread Pierre-Alain Dorange
BartC wrote: > But even with ordinary conditionals, False is False, but [False] is > True. And [] is False, while [[]] is True. A class instance is always > True, even when empty. And then "False" is True as well! "Empty" is not "Nothing". To be empty, something must exist first. -- Pierre-Al

Re: Break and Continue: While Loops

2016-06-23 Thread John Gordon
In <639b00e0-7b9d-4ed4-96ad-6afbcd536...@googlegroups.com> Elizabeth Weiss writes: > 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? Your code prints i and THEN adds one to it. So i is

Re: Break and Continue: While Loops

2016-06-23 Thread Chris Angelico
On Fri, Jun 24, 2016 at 1:52 AM, BartC wrote: > On 23/06/2016 12:39, Chris Angelico wrote: >> >> On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >>> >>> Actually pretty much any expression can be used, because Python can >>> interpret almost anything as either True or False. Don't ask for the >>> r

Re: Break and Continue: While Loops

2016-06-23 Thread BartC
On 23/06/2016 12:39, Chris Angelico wrote: On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: Actually pretty much any expression can be used, because Python can interpret almost anything as either True or False. Don't ask for the rules because they can be complicated, but for example, zero is False

Re: Break and Continue: While Loops

2016-06-23 Thread Jon Ribbens
On 2016-06-23, Chris Angelico wrote: > On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: >> Actually pretty much any expression can be used, because Python can >> interpret almost anything as either True or False. Don't ask for the rules >> because they can be complicated, but for example, zero is Fa

Re: Break and Continue: While Loops

2016-06-23 Thread Chris Angelico
On Thu, Jun 23, 2016 at 8:15 PM, BartC wrote: > Actually pretty much any expression can be used, because Python can > interpret almost anything as either True or False. Don't ask for the rules > because they can be complicated, but for example, zero is False, and any > other number is True. I thin

Re: Break and Continue: While Loops

2016-06-23 Thread BartC
On 23/06/2016 05:17, Elizabeth Weiss wrote: CODE #1: i=0 while True: i=i+1 if i==2: print("Skipping 2") continue if i==5: print("Breaking") break print(i) -- Questions: 2. i=i+1- I never understand this. Why isn't it i=i+2? 3. Do the results not include 2 of

Re: Break and Continue: While Loops

2016-06-23 Thread alister
On Wed, 22 Jun 2016 21:17:03 -0700, Elizabeth Weiss wrote: > CODE #1: > > i=0 while 1==1: >print(i) >i=i+1 if i>=5: > print("Breaking") break > > -- > I understand that i=0 and i will only be printed if 1=1 The results of > this is 0 > 1 > 2 > 3 > 4 > Breaking > > Why is Breaki

Re: Break and Continue: While Loops

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 14:17, Elizabeth Weiss wrote: > CODE #2: > > i=0 > while True: >i=i+1 > if i==2: > print("Skipping 2") > continue > if i==5: > print("Breaking") > break >print(i) > > -- > > Questions: > 1. what does the word True have to do with anyt

Re: Break and Continue: While Loops

2016-06-22 Thread Rustom Mody
On Thursday, June 23, 2016 at 9:47:23 AM UTC+5:30, Elizabeth Weiss wrote: > CODE #1: > > i=0 > while 1==1: >print(i) >i=i+1 >if i>=5: > print("Breaking") > break > > -- > I understand that i=0 and i will only be printed if 1=1 > The results of this is > 0 > 1 > 2 > 3 > 4

Re: Break and Continue: While Loops

2016-06-22 Thread Lawrence D’Oliveiro
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 printi

Break and Continue: While Loops

2016-06-22 Thread Elizabeth Weiss
CODE #1: i=0 while 1==1: print(i) i=i+1 if i>=5: print("Breaking") break -- I understand that i=0 and i will only be printed if 1=1 The results of this is 0 1 2 3 4 Breaking Why is Breaking going to be printed if i only goes up to 4? It does say if i>=5? Shouldn't this me