1. exit command

Dear Devs,

Sorry, can not find the 3.x 'exit' command in Manual of 4.0.

Regards,
Igor Kachan
kinz@peterlink.ru

new topic     » topic index » view message » categorize

2. Re: exit command

kinz said...

Dear Devs,

Sorry, can not find the 3.x 'exit' command in Manual of 4.0.

It's there. The manual is going to undergo some changes to make it easier to find things, it is a bit difficult to locate them right now. What you want is:

http://openeuphoria.org/docs/eu400_0009.html#_59_LanguageReference

Specifically:

http://openeuphoria.org/docs/eu400_0015.html#_121_exitstatement

Jeremy

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

3. Re: exit command

jeremy said...
kinz said...

Dear Devs,

Sorry, can not find the 3.x 'exit' command in Manual of 4.0.

It's there. The manual is going to undergo some changes to make it easier to find things, it is a bit difficult to locate them right now. What you want is:

http://openeuphoria.org/docs/eu400_0009.html#_59_LanguageReference

Specifically:

http://openeuphoria.org/docs/eu400_0015.html#_121_exitstatement

Jeremy

Thanks, found.
But why not to use the clear BASIC form 'exit [[do]if|switch]' instead of 'exit' and 'break'? Just curious. Same action, but two different keywords.
BEu sorry again.

Regards,
Igor Kachan
kinz@peterlink.ru

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

4. Re: exit command

kinz said...

Thanks, found.

But why not to use the clear BASIC form 'exit [[do]if|switch]' instead of 'exit' and 'break'? Just curious. Same action, but two different keywords.

BEu sorry again.

The BASIC for is very limited. Two words were adopted because break from a if/switch doesn't happen that often and we didn't want to require having a label, which if we used just one word we would have to label just about everything. Here is an example:

for i = 1 to 10 do 
    for j = 10 to 1 by -1 do 
        if j > 5 then  
            exit for 
        end if 
    end for 
end for 

What would happen?

Now, say we use the same word for everything:

for i = 1 to 10 do 
    for j = 10 to 1 by -1 do 
        switch j do 
            case 1 do 
                exit 
        end switch 
    end for 
end for 

Now, in the above situation, since we use two keywords, it's clear that exit will exit from the loop. exit leaves loops, break leaves decision constructs. Now, we use labels instead of the BASIC [for|while|if|loop] construct for this reason:

for i = 1 to 10 label "top" do 
    for j = 1 to 10 label "middle" do 
        for k = 1 to 10 do 
            if k = 5 then exit end if -- exits for k = 1 to 10 
            if k = 3 then exit "middle" end if -- exits for j = 1 to 10 
            if k = 2 then exit "top" end if -- exits for i = 1 to 10 
        end for 
    end for 
end for 

If you only have the ability to exit one loop at a time, you must introduce a state variable which is a mess:

integer break_i=0, break_j=0 
 
for i = 1 to 10 label "top" do 
    for j = 1 to 10 label "middle" do 
        for k = 1 to 10 do 
            if k = 5 then  
                exit for -- exits for k = 1 to 10 
            end if              
            if k = 3 then  
                break_j = 1 
                exit for -- exits for k = 1 to 10 
            end if  
            if k = 2 then  
                break_j = 1 
                break_i = 1 
                exit for -- exits for k = 1 to 10 
            end if  
        end for 
 
        if break_j then 
            break_j = 0 -- reset flag 
            exit for 
        end if 
    end for 
 
    if break_i then 
        break_i = 0 -- reset flag for clarity 
        exit for 
    end if 
end for 

Jeremy

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

5. Re: exit command

jeremy said...
kinz said...

Thanks, found.

But why not to use the clear BASIC form 'exit [[do]if|switch]' instead of 'exit' and 'break'? Just curious. Same action, but two different keywords.

BEu sorry again.

The BASIC for is very limited. Two words were adopted because break from a if/switch doesn't happen that often and we didn't want to require having a label, which if we used just one word we would have to label just about everything. Here is an example:

for i = 1 to 10 do 
    for j = 10 to 1 by -1 do 
        if j > 5 then  
            exit for 
        end if 
    end for 
end for 

What would happen?

Now, say we use the same word for everything:

for i = 1 to 10 do 
    for j = 10 to 1 by -1 do 
        switch j do 
            case 1 do 
                exit 
        end switch 
    end for 
end for 

Now, in the above situation, since we use two keywords, it's clear that exit will exit from the loop. exit leaves loops, break leaves decision constructs. Now, we use labels instead of the BASIC [for|while|if|loop] construct for this reason:

for i = 1 to 10 label "top" do 
    for j = 1 to 10 label "middle" do 
        for k = 1 to 10 do 
            if k = 5 then exit end if -- exits for k = 1 to 10 
            if k = 3 then exit "middle" end if -- exits for j = 1 to 10 
            if k = 2 then exit "top" end if -- exits for i = 1 to 10 
        end for 
    end for 
end for 

If you only have the ability to exit one loop at a time, you must introduce a state variable which is a mess:

integer break_i=0, break_j=0 
 
for i = 1 to 10 label "top" do 
    for j = 1 to 10 label "middle" do 
        for k = 1 to 10 do 
            if k = 5 then  
                exit for -- exits for k = 1 to 10 
            end if              
            if k = 3 then  
                break_j = 1 
                exit for -- exits for k = 1 to 10 
            end if  
            if k = 2 then  
                break_j = 1 
                break_i = 1 
                exit for -- exits for k = 1 to 10 
            end if  
        end for 
 
        if break_j then 
            break_j = 0 -- reset flag 
            exit for 
        end if 
    end for 
 
    if break_i then 
        break_i = 0 -- reset flag for clarity 
        exit for 
    end if 
end for 

Jeremy

Thanks, I see, but, sorry, my expectations (I code 12 years in EU) were:

'exit' for exiting of 'do' cycles (for..end for, while..end while, new loop),
'exit if'
new mode for 'if..end if'
'exit switch' new mode for 'switch..end switch'

The above 'exits' are self-explaining in EU, but 'break' needs a separate page in docs just to explain that it is same as exit, but for if and switch.

BTW, Quick Basic 4.5 has EXIT {DEF | DO | FOR | FUNCTION | SUB}.

So, 'break' seems to be a superfluous key word in EU 4.0.

IMHO and my $0.005.

Regards,
Igor Kachan
kinz@peterlink.ru

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

Search



Quick Links

User menu

Not signed in.

Misc Menu