1. else on for

--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">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; 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">&gt; 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">&gt; 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">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;    for i = 1 to length( s
)</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;       if s[i] = 999
then</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;         
break</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;       end
if</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;    else</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;       printf( &quot;999
was not found&quot; )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;    end for</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; 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">&gt; cheap to implement.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </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( &quot;999 WAS
found!!&quot; )</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--

new topic     » topic index » view message » categorize

2. Re: else on for

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: else on for

--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">&gt; ============ The Euphoria Mailing List ============
</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; Karl Bochert wrote:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; 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">&gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;     for i = 1 to length( s
)</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;        if
s[i] = 999 then</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt;
&gt;          
break</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;        end
if</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;     else</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;       
printf( &quot;999 WAS found!!&quot; )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;     end
for</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; 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">&gt; 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">&gt; 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">&gt; </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
(&quot;999 NOT found&quot;)</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 &amp; 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--

new topic     » goto parent     » topic index » view message » categorize

4. Re: else on for

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: else on for

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. smile

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

6. Re: else on for

> Yes, except that EXIT will trigger the ELSE clause. I just report the
> behavior, I don't make it up. smile

D'oh! I meant, EXIT _won't_ trigger the ELSE clause. Maybe I do just make this 
stuff up, after all.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

7. Re: else on for

Hi David, you wrote:

>> Yes, except that EXIT will trigger the ELSE clause. I just report the
>> behavior, I don't make it up. smile
>
> 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     |

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu