HelloIDistance Posted June 9, 2004 Share Posted June 9, 2004 Is it possible to name "while" functions, so that when you use two "while" commands it will know which "while" to end? Link to comment Share on other sites More sharing options...
Valik Posted June 9, 2004 Share Posted June 9, 2004 (edited) Wend terminates the first While loop it finds. It's called scope. Nesting While loops inside any other while, do, for, or if structure is possible. Most people use tabs to help space their script to show scope.While 1 ; Scope 1 DoSomething() ; Scope 2 If 1 = 2 Then ; Scope 2 SystemError() ; Scope 3 Else ; Scope 2 $a = 1 ; Scope 3 While $a < 5 ; Scope 3 DoMore() ; Scope 4 $a = $a + 1 ; Scope 4 Wend EndIf WendEdit: Silly forum doesn't like my spacing... Edited June 9, 2004 by Valik Link to comment Share on other sites More sharing options...
tutor2000 Posted June 9, 2004 Share Posted June 9, 2004 Is it possible to name "while" functions, so that when you use two "while" commands it will know which "while" to end?Wouldn't you do your exitloop priorities in the function?Rick Link to comment Share on other sites More sharing options...
Developers Jos Posted June 9, 2004 Developers Share Posted June 9, 2004 Is it possible to name "while" functions, so that when you use two "while" commands it will know which "while" to end?Wend always ends the last While. When you use proper tabbing you can easily see which one you are ending. Also when you use an editor like Scite, you can use code folding, which will make it easy to see which one you'r closing.... You could put a comment behind it like: While 1 ; first level ; somecode While 1 ; level 2 ; some other code Wend ; Level 2 Wend ; Level 1 SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Josbe Posted June 9, 2004 Share Posted June 9, 2004 (edited) In general, you can end a While conditionally, or with ExitLoop n inside.n: The level.Edit: Format Edited June 9, 2004 by josbe • AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 9, 2004 Author Share Posted June 9, 2004 Thanks for all the quick replys. I still don't understand though :/. Maybe if I show an example: While 1 ;code While 2 ;code WEnd; I want to end the first while though not the second ;code WEnd; End the second while How would I do that? I tryed the ExitLoop command, but it didn't work. Is it possible to do that? Sorry if this was answered before I don't understand. Link to comment Share on other sites More sharing options...
pekster Posted June 9, 2004 Share Posted June 9, 2004 I want to end the first while though not the secondYou can't do that. But there should never be a need to. Instead, switch the the ;code segments around, so that you end the other one in the 2nd While- WEnd pair. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 9, 2004 Author Share Posted June 9, 2004 You can't do that. But there should never be a need to. Instead, switch the the ;code segments around, so that you end the other one in the 2nd While- WEnd pair.Ah, okay. I never thought about switching it around .Thanks! Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 (edited) Alright after messing with this timer for a long time I still don't get it. I have tried to switch it around. I have tried to use ExitLoop, ContinueLoop. Here is an example of my problem: Global $hTimer = TimerStart() While 1 If TimerStop($hTimer) >= (10000) Then Reconnect() $Hellowall = 2 Sleep(1000) Send ("Howdy Partner!") While $Hellowall > 1 Send ("Hahahaha") Sleep(2000) WEnd WEnd Func Reconnect() Sleep(20000) Send ("It worked!") Sleep(1000) $hTimer = TimerStart(); Reset timer EndFunc With this it never gets to my Func Reconnect(). I have tried to use an If..Then instead While..WEnd, but it doesn't work the same. Any ideas on how to fix this? Edited June 10, 2004 by Larry Link to comment Share on other sites More sharing options...
Josbe Posted June 10, 2004 Share Posted June 10, 2004 hmmm...I think that, the problem is with your Loop :While $Hellowall > 1 Send ("Hahahaha") Sleep(2000) WEndBecause, $Hellowall is greater than 1, this repeats infinitely.$Hellowall variable needs change in some time? • AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
SlimShady Posted June 10, 2004 Share Posted June 10, 2004 You made an infinite loop. If you want to get out of it, the $Hellowall variable has to change. Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 (edited) Ah, That is my problem. I get it now, but how would I change the variable and still get the timer to run every ten seconds, and then that loop to run again? After it does the func Reconnect()? Edited June 10, 2004 by HelloIDistance Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 Bump^ Link to comment Share on other sites More sharing options...
pekster Posted June 10, 2004 Share Posted June 10, 2004 (edited) but how would I change the variable and still get the timer to run every ten seconds, and then that loop to run again?The variable changes by assigning a new value to it. Like $var = $var -1 or $var = $var +1 to decrease or increase it by one. If you need to test for the timer in both loops, why not call your conditional statement in the 2nd loop as well as the first? As long as the timer is reset before it comes out of the timer handeling function, it won't interfere (as long as running the timer handeling function is not a problem from within the 2nd loop.)Edited to fix my vars so they matched Edited June 10, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 Okay I am kind of confused your saying I should decrease the value of the variable to one so it doesn't loop then change it back to two? Sorry I'm sorta confused could you write an example? Link to comment Share on other sites More sharing options...
pekster Posted June 10, 2004 Share Posted June 10, 2004 I'm sorta confused could you write an example?Your loop has no way out of it since you start with a variale larger than 1, and tell it to do some stuff while that variable is larger than one. It will always be larger than one, and therefore you will never get out of that loop unless you ExitLoop, or use a seperate function call (or AdLib) to get out. Here is a basic example of incrimenting a variable in a while loop. Please note that this is only a simple example, and technically a For loop would be more useful, but I'm trying to demonstrate keeping as much of your code as I can. While $Hellowall > 1 Send ("Hahahaha") Sleep(2000) $Hellowall = $Hellowall - 1 WEnd That will decrease $Hellowall by 1 each time the loop is run. When it is 1, you will exit the loop. If not, you will keep decreasing it until it is. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 Okay, so would ExitLoop before the loop work? How would I re-enter the loop? Is it possible then to run the $Hellowall loop and the Timer loop? Link to comment Share on other sites More sharing options...
pekster Posted June 10, 2004 Share Posted June 10, 2004 (edited) What are you trying to do? If you nest loops (that means putting a loop inside another loop) it will do the following:Run the main body of your 1st while loop (up to the 2nd While command)Run the main body of your 2nd while loopIf the condition for your 2nd while loop is true, go to step #2Run any steps in the main body of your 1st while loop that are after the WEnd of the 2nd while loopIf the condition for your 1st while loop is true, go to step #1Understand that you will keep doing step #2 over and over until the condition (see #3) is false. If this is not what you want, then don't nest your statements, and only use one loop to test the timer, and then do other stuff, and go back to the top of the loop again.Technical note: (Edit) Technically the loop is testing the condition before it runs the loop, so you could run a while loop 0 times. However, when I wrote these example steps, I wasn't thinking about it, so it doesn't show excatally how the computer is thinking about it. But it's close enough to understand what nesting is, and to make sure you actually want to nest your while functions. Edited June 10, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
SlimShady Posted June 10, 2004 Share Posted June 10, 2004 What are you trying to do?That's the question you should answer first... Link to comment Share on other sites More sharing options...
HelloIDistance Posted June 10, 2004 Author Share Posted June 10, 2004 What are you trying to do?I just wanna get this thing to work, lol. Okay, I think I know what your talking about. I want to keep it the same but just have both loops work (Is this possible?). I want it them both to work within each other. What would I change to make it work? Like if your using the same script as the one I posted is it possible to have them both run together? How would I do that?If I changed the variable then it would quit looping correct? So maybe I don't want to nest my statements. Then how would I unnest them? Sorry for all the noobish questions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now