Exit scope

General FreeBASIC programming questions.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Exit scope

Postby Gonzo » Nov 19, 2011 1:03

is it possible to add the possibility for early exiting a scope?
it would be very useful to me...

right now i have a macro that i dont want to turn into a function,
and it needs to be run several times... so theres no option for a goto
its the kind of macro that putting a do loop inside would make no sense
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Nov 19, 2011 2:24

Scope
...
End Scope

???

-Vince
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Postby Gonzo » Nov 19, 2011 3:00

what?
i have a huge macro that i want to encapsulate in a scope
at some points inside that macro i want to Exit Scope
just like a Return in a function...
its code that would be a nightmare to turn into a function, and would reduce overall speed of code.. its not happening
its also the biggest bottleneck, so whatever i have to do, i will do it
exit scope would have been very useful, but i disabled some features and made it run by using a few extra if tests.. if i enable these features i NEED to be able to jump in the code, inside a macro..

come to think of it, it would be possible to:
#macro stuff(jumpto)

goto jumpto
#endmacro
right? thats one way i guess =)
pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Postby pestery » Nov 19, 2011 12:53

You could use a Do ... Loop instead of Scope ... End Scope. Then you can use the Exit Do statement.

Code: Select all

Do
   ' Some code
   If condition Then Exit Do
   ' Some more code
   Exit Do
Loop
counting_pine
Site Admin
Posts: 6228
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Nov 19, 2011 13:48

Yeah, a 'Do..Loop While 0' block is effectively equivalent to a Scope.
fxm
Posts: 9983
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Postby fxm » Nov 19, 2011 14:16

counting_pine wrote:Yeah, a 'Do..Loop While 0' block is effectively equivalent to a Scope.

Yes, and it is faster than 'Do ... Exit Do : Loop'!
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Postby Gonzo » Nov 19, 2011 15:37

yea that works too, thanks :)
dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Exit scope

Postby dodicat » Nov 19, 2011 15:47

Gonzo wrote:is it possible to add the possibility for early exiting a scope?
it would be very useful to me...

right now i have a macro that i dont want to turn into a function,
and it needs to be run several times... so theres no option for a goto
its the kind of macro that putting a do loop inside would make no sense

You can have goto alright, if you give the macro a different label each call

Code: Select all


#macro getmeout(label)
scope
    k=k+1
    dim as string dummy="Just passing through   @ " & str(k+25)
for z as integer=1 to 50
    if z=25+k then
        print dummy
goto label
end if
next z
label
end scope
#endmacro


dim as integer k
getmeout(oot:)
getmeout(finish:)
getmeout(free:)
getmeout(thankyou:)
sleep
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Postby Gonzo » Dec 10, 2011 23:50

can confirm that using goto labels for macro parameters made it work as expected =)

i would have preferred exit scope! but its ok
it was a multiple goto-thing.. it would have been ugly code with lots of always-ending loops =)
counting_pine
Site Admin
Posts: 6228
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Dec 11, 2011 0:25

You could stop it looking like a loop by hiding the blocks in macros:

Code: Select all

#define _scope do
#define end_scope loop while 0

_scope

    '...

    exit _scope

    '...

end_scope
Either way it's nicer than any Goto-based solution, and it avoids having to invent multiple Goto labels.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Postby Gonzo » Dec 11, 2011 0:36

yea, thats a neat trick
i think ill do that, since its a little bit prettier again :D

thanks!
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Re: Exit scope

Postby agamemnus » Nov 11, 2013 0:51

bump
D.J.Peters
Posts: 8188
Joined: May 28, 2005 3:28
Contact:

Re: Exit scope

Postby D.J.Peters » Nov 11, 2013 2:25

agamemnus wrote:bump
Any questions ?

I wonder me what dodicat posted at Sat Nov 19, 2011

Code: Select all

if z=25+k then
Looks as C/C++ code for me.

I did not that FreeBASIC evaluates an assignment in a if expression ?

Joshy
counting_pine
Site Admin
Posts: 6228
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Exit scope

Postby counting_pine » Nov 11, 2013 2:58

D.J.Peters wrote:

Code: Select all

if z=25+k then
Looks as C/C++ code for me.

I did not that FreeBASIC evaluates an assignment in a if expression ?

It's an equality test. FB doesn't have '=='.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Re: Exit scope

Postby agamemnus » Nov 13, 2013 7:44

Any chance of this happening, or 0.

Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests