Sign in to follow this  
Followers 0

Help with "While"... the new 'goto'

5 posts in this topic

Posted

I read this in the FAQ about the old 'goto' function...

Just to get you started, the most basic use of Goto in version 2.64 was an infinite loop like:

:mylabel

...do something...

...and something else...

goto, mylabel

A simple v3 version of that is a While loop that is always "true".

While 1 = 1

...do something...

...do something else...

Wend

That above makes sense... but I do believe with the goto function you would be able to tell the script to 'goto another section' of the script, where as the while 1 = 1 loop will only loop whats within 'While' and 'Wend'...

with the old 'goto' function (i never used it) but im guessing you'd be able to acheive something similar to this:

:mylabel

...do something...

...and something else...

goto, :helpme

:helpme

...do something...

...and something else...

goto, :please

:please

...do something...

...and do something else...

goto, :helpme

Instead of looping from ":mylabel" to ":mylabel" like the example in the FAQ section... the script above actually tells the script to go from one loop to another loop... I want to know how to do this with the "While" function

I have read all through the Functions help file for anything relative towards what im in search of, but i cant find anything... I'm hoping that an expert on here can explain to me how to do the following without directing me back to the help file on the account of I'm totally new at this and have no idea...

Thanks

Share this post


Link to post
Share on other sites



Posted

reecedorward,

Why not create a custom function like:

Func _MyGoToFunction()
    ;Do my Goto needs here
EndFunc

Then whenever you need to call that portion of your script all you have to do is call it like so:

If $Do_I_need_ToGo Then _MyGoToFunction()

It's actually better than a GoTo call as old school programming used, since it runs the portion of needed script, then returns back to where it left off before.

Realm

Share this post


Link to post
Share on other sites

Posted

AH HA! Thanks Realm

That has helped a lot! I will give that a go and post the results in here when its done ;)

Also, with the line Func _MyGoToFunction () ..... what are the end brackets for?

Cheers,

Reece

Share this post


Link to post
Share on other sites

Posted

It's explained nicely in the Help file - Language Reference - User Functions ;)

Share this post


Link to post
Share on other sites

Posted

reecedorward,

Remove the useless labels and gotos in your last example and you're left with a simple sequence of instructions, since there is no loop in your pseudo-code.

OTOH, what guys are suggesting is bad. A much better idea is to restructure the code to blocks and true functions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.