theimmortalbg 0 Posted September 8, 2013 (edited) Hello, this is my code While 1 If someFunc() Then $var1 = otherFunc() ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " " & $var1 & @CRLF) ExitLoop EndIf WEnd The problem here is that ExitLoop exits form while loop. I want to break only the if statement. How I can do it without change the if condition? (someFunc() always return true) Edited September 8, 2013 by theimmortalbg Share this post Link to post Share on other sites
Newb 5 Posted September 8, 2013 You gotta set another condition (or a double if condition). Example I wanna run an if statement if the number of apples is >50 and only on Saturday While 1 If $Apples>50 And DayFunc() == Saturday Then ;Do Stuff EndIf While 1 If $Apples>50 Then If DayFunc() == "Saturday" ;Do Stuff EndIf EndIf Both of those with a righ set condition, will not enter the If loop. If it's not a loop but a logic operator, hence why you gotta exit it with a condition and not an ExitLoop. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Share this post Link to post Share on other sites
water 2,359 Posted September 8, 2013 Welcome to Autoit and the forum! As someFunc always returns True your script could be stripped down to While 1 someFunc() $var1 = otherFunc() ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " " & $var1 & @CRLF) WEnd My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
JibsMan 2 Posted August 8, 2014 I realize the post is old; I was looking for a solution for this. ExitLoop does not work with If Statements. And you don't need it. Do this: If Test = True Then ;just leave this line blank or no blank line between If and ElseIf. ElseIf Test = False Then DoSomething() Else DoSomethingElse() EndIf MsgBox ($MB_OK, "Info", "Test was True") Eh, it worked for me. Share this post Link to post Share on other sites
NDog 0 Posted January 9, 2018 (edited) What If I have a really long nested If statement or contained within a function, and I need to break out of if,else,elseif statment though? eg Func X() Do stuff If $x = 0 Then Do Stuff Else Do Stuff -- >I want to leave if statement if something doesn't work here to avoid Doing more stuff Doing more Stuff EndIf More stuff EndFunc According to the posters logic above I should rewrite all my If statements to seperate functionS? Edited January 9, 2018 by NDog Share this post Link to post Share on other sites
Earthshine 511 Posted January 9, 2018 Long nested if statements are never a way to go My resources are limited. You must ask the right questions Share this post Link to post Share on other sites
ViciousXUSMC 92 Posted January 9, 2018 If you only have 2 result conditions you do not need the 2nd IF just an Else. Because if its not true then by elimination it must be false. If $condition = True Then ;Do something Else ;Do something else EndIf When you have multiple conditions, that is often times when the Case/Switch syntax can be used. 1 Earthshine reacted to this Share this post Link to post Share on other sites
LarsJ 1,010 Posted January 9, 2018 You do it this way. Use ExitLoop to quit your If statement at any point: While 1 If $x = 0 Then Do Stuff Else Do Stuff -- >I want to leave if statement if something doesn't work here to avoid Doing more stuff Doing more Stuff EndIf ExitLoop WEnd 1 Earthshine reacted to this File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsControl related: Hot-Track Enabled Toolbar Menu, Simulating a modeless Choose Color Dialog, Colors and fonts in TreeViewsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Share this post Link to post Share on other sites
LarsJ 1,010 Posted January 9, 2018 If you need a While loop as in the first post, you go this way: While 1 While 1 If $x = 0 Then Do Stuff Else Do Stuff -- >I want to leave if statement if something doesn't work here to avoid Doing more stuff Doing more Stuff EndIf ExitLoop WEnd ; Do Stuff WEnd 1 Earthshine reacted to this File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsControl related: Hot-Track Enabled Toolbar Menu, Simulating a modeless Choose Color Dialog, Colors and fonts in TreeViewsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Share this post Link to post Share on other sites
Earthshine 511 Posted January 9, 2018 (edited) spaghetti logic is UN-maintainable and a complete waste of time. use the while loops and switch/case statements when necessary structured logic, always please. you will do well and go far if you heed those words. Edited January 9, 2018 by Earthshine My resources are limited. You must ask the right questions Share this post Link to post Share on other sites
LarsJ 1,010 Posted January 9, 2018 But that was not the question. Neither in the first nor fifth post. Why do you rule out that both theimmortalbg and NDog have not already made these considerations? File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsControl related: Hot-Track Enabled Toolbar Menu, Simulating a modeless Choose Color Dialog, Colors and fonts in TreeViewsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Share this post Link to post Share on other sites