Jump to content



Photo

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


  • Please log in to reply
4 replies to this topic

#1 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 28 April 2012 - 01:35 AM

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





#2 Realm

Realm

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 608 posts

Posted 28 April 2012 - 02:40 AM

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
...and then we shall see if your insanity can be cured!______________________________________________________________________My Contributions: RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.

#3 reecedorward

reecedorward

    Seeker

  • Active Members
  • 27 posts

Posted 28 April 2012 - 02:53 AM

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

#4 somdcomputerguy

somdcomputerguy

  • Active Members
  • PipPipPipPipPipPip
  • 2,375 posts

Posted 28 April 2012 - 03:31 AM

It's explained nicely in the Help file - Language Reference - User Functions ;)
- Bruce /* somdcomputerguy */If you change the way you look at things, the things you look at change.

#5 jchd

jchd

    Whatever your capacity, resistance is futile.

  • MVPs
  • 3,250 posts

Posted 28 April 2012 - 04:13 AM

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.
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQL tutorial (covers generic SQL, but most of it apply to SQLite as well)An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious workPCRE v8.32 regexp pattern documentation. AutoIt uses a slightly older version so that more advanced features are not all available.RegExp tutorial: enough to get started




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users