Sign in to follow this  
Followers 0
qwerz123

Fully skipping the loop if variable in function is 0

8 posts in this topic

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

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

Share this post


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

Now that is what you call service! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


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

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!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

 

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