Sign in to follow this  
Followers 0
AhmedSabry32

Break While/Do Loops

13 posts in this topic

#1 ·  Posted (edited)

Ok , first of all in C++ Break means Exit the While Loop , but in Autoit ExitLoop means Exit the Script so i want an example to stop the loop without exiting the whole script

my code is :

Func _StopLoop()
   Global $off = 2
    EndFunc

Func _Loop()
    Global $off = 0
Do
While 1
    If _IsPressed("12") Then
        MouseClick("Left")
    EndIf
Until $off > 0
Return
EndFunc

I tried that with HotKeySet but it don't stop the loop and when i use Exit Loop it exit the script and when i use While NOT $off > 0 all of this exits the script

So please give me an example without closing the script.

Edited by AhmedSabry32

Share this post


Link to post
Share on other sites



Exit means exit the script. ExitLoop means exit the loop.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Exit means exit the script. ExitLoop means exit the loop.

then why when i use Exit Loop it exits the script?

Share this post


Link to post
Share on other sites

If there is nothing to execute after the loop exits, then the script will exit.

#include <GUIConstantsex.au3>
GUICreate("autoIT",300,100)
GUISetState(@SW_SHOW)

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Then this code you posted the Script will exit because nothing to excute after the Exit Loop right?

In this case there must be code under the Exit Loop?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Once AutoIt processes the ExitLoop, it goes back to the line after where it entered the loop. If you have nothing more, it is going to close:

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
_Loop1()
;Nothing here, so script exits

Func _Loop1()
While 1
If _IsPressed(01, $hDLL) Then ExitLoop
WEnd
;Press left mouse button, jump back to line 4
EndFunc

If, however, you do this, it won't exit:

#include <Misc.au3>
Local $hDLL = DllOpen("user32.dll")
_Loop1()
Msgbox(0, "", "Exited Loop")

Func _Loop1()
While 1
If _IsPressed(01, $hDLL) Then ExitLoop
WEnd
;Press left mouse button, jump back to line 4
EndFunc
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

You are correct. This is why Functions are glorious.

Share this post


Link to post
Share on other sites

Is there's an example of using the code inside Hotkeyset because i don't Use the Function out side only in HotKeySet and Case $button so i want it do only this without msg box and what else , I mean like this :

HotKeySet("{END}", "_Loop")

While 1
$nmsg = GUIGetMsg()
Switch $nmsg
Case $Button1
_Loop()
EndSwitch
WEND


Func _Loop()
While 1
If _IsPressed("01") Then
MouseClick("Left")
EndIf
ElseIf _IsPressed("02") Then
ExitLoop
WEND

Share this post


Link to post
Share on other sites

AhmedSabry32, what is the application or window you're trying to MouseClick on? There is probably a far easier way to accomplish this...


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

AhmedSabry32, what is the application or window you're trying to MouseClick on? There is probably a far easier way to accomplish this...

Well I'm using it as Example so idk how to do exit the loop without exiting the script without adding more codes

Share this post


Link to post
Share on other sites

Considering his last 3 locked threads, I'd say it's either some kind of game, game hack, or malware.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

My thoughts, as well. Especially as a GUI is referenced but we are not seeing the part of the code...


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

My thoughts, as well. Especially as a GUI is referenced but we are not seeing the part of the code...

Well I'm doing A Programme If a key is pressed it will do mouse click it has useful things like when you have no mouse .

Umm How can i Break It without adding more codes to it because idk what to add also this is the main script which i edited in the topic.

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