Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Please Explain How While Wend Infinite Loop Works

$
0
0

Hi,

 

I fundamentally don't know how this While... Wend loop works in relation to other code in the script - could someone please provide an explanation.

AutoIt         
Local $aPos[2] ;Declaring an array to hold mouse coordinates. HotKeySet("!m", "GetMouseCoords") ;Capture the current mouse coordinates <Alt>+m. HotKeySet("!{SPACE}", "SaveToFile") ;Start the 'Save File' function <Alt>+<Space>. HotKeySet("!{ESC}", "Terminate") ;Exit from the script/program <Alt>+<Esc>. While 1 ;This keeps the script permanently running until 'exit' hotkey pressed.     Sleep(100) WEnd Func GetMouseCoords()     $aPos = MouseGetPos() ;Capture the current mouse coordinates. EndFunc   ;==>GetMouseCoords Func SaveToFile()     MouseMove($aPos[0], $aPos[1]) ;Moves the mouse to the previously captured mouse coordinates.     ; <Other lines of code would follow here.> EndFunc   ;==>SaveToFile Func Terminate()     Exit ;Exit the script/progam. EndFunc   ;==>Terminate

Where I have the problem is that, as far as know - based on what I've read in the AutoIt help file - the above While... Wend loop is an infinite loop. My understanding of an 'infinite loop' is that the loop is entered in the functioning program and there the program gets 'stuck'/'locked in that loop'. Yet this can't be what is happening here - after all the program still monitors the keyboard for HotKey presses, and, if one of the hotkeys is pressed, then the program (correctly) goes to one of the three functions and (correctly) executes whatever instructions are contained inside the function. How can the program do this if it is stuck in an infinite loop - should it not just be perpetually looping in the loop? How does it (seemingly) jump of the loop to check the keyboard and then jump back in the loop to keep the program perpetually running (till the 'exit' key is pressed)?

 

(I hope I've explained the problem well enough for people to get a handle on what I'm trying to say. I'm really asking a 'concept question' I suppose - I don't understand how the program does anything other than stay in the loop. I also suspect that it is 'staying in that loop' that allows the program to constantly run monitoring for key-presses - instead of just on launching the program the program runs for a split second then just exits from itself.)


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>