1. else on for
- Posted by kbochert at copper.net Aug 08, 2003
- 441 views
--Alt-Boundary-10696.1125213 Content-description: Mail message body On 6 Aug 2003 at 20:36, David Cuny wrote: > > I've implemented REDO, BREAK and CONTINUE in my own BASIC interpreter. > Additionally, there is a ELSE clause on all the control structures, so if > they complete without hitting a BREAK clause, the THEN executes: > > for i = 1 to length( s ) > if s[i] = 999 then > break > end if > else > printf( "999 was not found" ) > end for > > It saves having to set up a flag marking that something was found, and is > cheap to implement. > I very much like this, 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 treating the 'break' as a sort of small-scale exception? A loop being expected to run to completion, and a break being abnormal? By analogy with 'if - else'; The 'else' only executes when the 'for' doesn't (completely) execute. Is 'else' the best name?? Any opinions? Karl Bochert --Alt-Boundary-10696.1125213 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 6 Aug 2003 at 20:36, David Cuny wrote:</span></font></div> <div align="left"><br/> </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've implemented REDO, BREAK and CONTINUE in my own BASIC interpreter. </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> Additionally, there is a ELSE clause on all the control structures, so if </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> they complete without hitting a BREAK clause, the THEN executes:</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 not 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">> It saves having to set up a flag marking that something was found, and is </span></font></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt">> cheap to implement.</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">I very much like this, but shouldn't the sense be reversed?</span></font></div> <div align="left"><br/></div> <div align="left"><font face="Arial" color="#7f0000"><span style="font-size:10pt"> </span></font><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"> else</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> printf( "999 WAS 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">treating the 'break' as a sort of small-scale exception?</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">A loop being expected to run to completion, and a break</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">being abnormal?</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">By analogy with 'if - else'; The 'else' only executes when the</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">'for' doesn't (completely) execute.</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Is 'else' the best name??</span></font></div> <div align="left"><br/> </div> <div align="left"><font face="Arial"><span style="font-size:10pt">Any opinions?</span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt"> </span></font></div> <div align="left"><font face="Arial"><span style="font-size:10pt">Karl Bochert</span></font></div> --Alt-Boundary-10696.1125213--
2. Re: else on for
- Posted by David Cuny <dcuny at LANSET.COM> Aug 08, 2003
- 430 views
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. -- David Cuny
3. Re: else on for
- Posted by kbochert at copper.net Aug 08, 2003
- 399 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--
4. Re: else on for
- Posted by Juergen Luethje <j.lue at gmx.de> Aug 08, 2003
- 414 views
Hi Karl, you wrote: > 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. I also like this idea in general, but totally agree with your worries. > 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. 'for ... then' is as confusing for me as 'for ... else'. > The not found clause is 'after' rather than 'otherwise'. That's also the way I understood it (but I don't know, if it's right.) BTW: Does 'break' have the same effect as 'exit'? How about this: for i = 1 to length( s ) if s[i] = 999 then exit end if finally printf ("999 NOT found") end for Best regards, Juergen -- The difference between men and boys is the price of their toys.
5. Re: else on for
- Posted by David Cuny <dcuny at LANSET.COM> Aug 08, 2003
- 402 views
Juergen wrote: > BTW: Does 'break' have the same effect as 'exit'? Yes, except that EXIT will trigger the ELSE clause. I just report the behavior, I don't make it up. -- David Cuny
6. Re: else on for
- Posted by David Cuny <dcuny at LANSET.COM> Aug 08, 2003
- 415 views
> Yes, except that EXIT will trigger the ELSE clause. I just report the > behavior, I don't make it up. D'oh! I meant, EXIT _won't_ trigger the ELSE clause. Maybe I do just make this stuff up, after all. -- David Cuny
7. Re: else on for
- Posted by Juergen Luethje <j.lue at gmx.de> Aug 08, 2003
- 438 views
Hi David, you wrote: >> Yes, except that EXIT will trigger the ELSE clause. I just report the >> behavior, I don't make it up. > > D'oh! I meant, EXIT _won't_ trigger the ELSE clause. Maybe I do just > make this stuff up, after all. > > -- David Cuny Ah, I see. Thanks for the clarification. Best regards, Juergen -- /"\ ASCII ribbon campain | \ / against HTML in | This message has been ROT-13 encrypted X e-mail and news, | twice for higher security. / \ and unneeded MIME |