Re: else on for
- Posted by kbochert at copper.net Aug 08, 2003
- 400 views
--Alt-Boundary-24703.13536828 Content-description: Mail message body On 7 Aug 2003 at 7:00, David Cuny wrote: > > > Karl Bochert wrote: > > > I very much like [else], but shouldn't the sense be reversed? > > > > for i = 1 to length( s ) > > if s[i] = 999 then > > break > > end if > > else > > printf( "999 WAS found!!" ) > > end for > > I see what you mean, but no. At least, not the way Python implements it, which > > is where I stole it from. Think of it this way: knowing the value was found > it the easy part. That it wasn't found is more problematic. > Interesting. It took a while, but I understand (and agree!). It is distressing that it could so thoroughly mislead me at first glance. It does seem that 'else' here has a very different behavior than the else in if-else. Maybe: for i = 1 to length( s ) if s[i] = 999 then break end if then printf ("999 NOT found") end for would be more consistant with the other uses of else & then. The not found clause is 'after' rather than 'otherwise'. Karl Bochert --Alt-Boundary-24703.13536828 Content-type: text/html; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body <?xml version="1.0" ?><html> <head> <title></title> </head> <body> <div align="left"><font face="Arial"><span style="font-size:10pt">On 7 Aug 2003 at 7:00, David Cuny wrote:</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> ============ The Euphoria Mailing List ============ </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Karl Bochert wrote:</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > I very much like [else], but shouldn't the sense be reversed?</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> ></span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > for i = 1 to length( s )</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > if s[i] = 999 then</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > break</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > end if</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > else</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > printf( "999 WAS found!!" )</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> > end for</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> I see what you mean, but no. At least, not the way Python implements it, which </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> is where I stole it from. Think of it this way: knowing the value was found </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> it the easy part. That it wasn't found is more problematic.</span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> </span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">Interesting. It took a while, but I understand (and agree!).</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">It is distressing that it could so thoroughly mislead me at first glance.</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">It does seem that 'else' here has a very different behavior than the else</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">in if-else.</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Maybe:</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt"> for i = 1 to length( s )</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> if s[i] = 999 then</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> break</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> end if</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> then</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> printf ("999 NOT found")</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> end for</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">would be more consistant with the other uses of else & then.</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">The not found clause is 'after' rather than 'otherwise'.</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Karl Bochert</span></font></div> <div align="left"><br/> </div> <div align="left"></div> --Alt-Boundary-24703.13536828--