Jump to content

Fully skipping the loop if variable in function is 0


Recommended Posts

Hello!

I would ask you guys is there a way to skip everything in a loop and begin again when variable in a function in the loop is 0? Sorry for my bad english better if i give an example

While 1
   Function1
   Function2
   Function3
WEnd

Func Function2
   $c=checkSomething()
   If $c=0 Then
     HERE -> ;some function to skip this function and Function3 in a loop and start again with function1
   EndIf
   function continues...
   function continues...
   function continues...
EndFunc

I know that i can make a variable and check at the beginning in every function in a loop but maybe there is a better way.

Thanks for your answers

Best regards

Link to comment
Share on other sites

  • Moderators

qwerz123,

Welcome to the AutoIt forum. ;)

Something like this should do what you want: :)

While 1
    Function1()
    If Function2() = 1 Then ; If the return was 1 we continue
        Function3()
    EndIf
WEnd

Func Function2()
    $c = checkSomething()
    If $c = 0 Then
        Return 0 ; Do not continue
    EndIf
    function continues...
    function continues...
    function continues...
    Return 1 ; Continue
EndFunc   ;==>Function2

Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi, qwerz123. It depends on where your variable is being set. You could do something like this:

Global $c

While 1
_Func1()
If $c <> 1 Then
  _Func2()
  _Func3()
EndIf
WEnd

Func _Func1()
MsgBox(0, "Test", "Hello 1!")
$c = 1
EndFunc

Func _Func2()
  MsgBox(0, "Test", "Hello 2!")
EndFunc

Func _Func3()
MsgBox(0, "Test", "Hello 3!")
EndFunc

Edit: !@##%$#@! ;)

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

Something like this?

While 1
   Function1
   Function2
   If @error <> 1 Then Function3
WEnd

Func Function2
   $c=checkSomething()
   If $c=0 Then Return SetError(1)
   function continues...
   function continues...
   function continues...
EndFunc

Exits the function and sets macro @error = 1. Function3 is executed only when @error <> 1.

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

  • Moderators

Now that is what you call service! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Three different solutions in the same minute ;) . qwerz123 it's now up to you to select a solution :)

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

Wow! Thanks guys!

I was thinking too same way like your examples. But when there 2 or 3 variables to check every time the code becomes more complicated for writing and reading. But that's ok. Creating something new is never a easy job, isn't it? ;)

Thanks again.

Best regards!

Link to comment
Share on other sites

While 1
   Function1
   If Not Function2 Then ContinueLoop
   Function3
WEnd

Func Function2
   $c=checkSomething()
   If $c=0 Then Return False
   function continues...
   function continues...
   function continues...
EndFunc

I can haz win?

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

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...