Jump to content

Break While/Do Loops


Recommended Posts

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
Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...