monax Posted November 28, 2013 Share Posted November 28, 2013 Hi, what is the best practice to write the next code in autoit (or any language)?: for $ii = 1 To 81 ;1+6*0 , 1+6*1, 1+6*2, 1+6*3, ... If $ii = 1 or $ii = 7 or $ii = 13 or $ii = 19 or $ii = 25 or $ii = 31 or $ii = 37 or $ii = 43 _ or $ii = 49 or $ii = 55 or $ii = 61 or $ii = 67 or $ii = 73 or $ii = 79 Then EndIf ;any numbers If $ii = 1 or $ii = 24 or $ii = 37 or $ii = 76 Then EndIf Next I would like to know if is possible to use an array to simplify the sintax. Something that looks like this $arr=[1,7,13,19,25] for $ii = 1 To 81 If $ii = $arr Then EndIf Next Of course I could use a 2nd loop to do this: $arr=[1,7,13,19,25] for $ii = 1 To 81 for $jj = 0 To 4 If $ii = $arr[$jj] Then EndIf Next Next But I want to know which is the clearest and simplest way to write it. Link to comment Share on other sites More sharing options...
monax Posted November 28, 2013 Author Share Posted November 28, 2013 I forgot to ask explicitly if there is a better way to write each case: 1) 1+6*0 , 1+6*1, 1+6*2, 1+6*3, ... 2) any numbers Link to comment Share on other sites More sharing options...
Solution water Posted November 28, 2013 Solution Share Posted November 28, 2013 (edited) Switch $ii Case 1, 7 .. 79 ; Statements Case Else ; Statements EndSwitch Edited November 28, 2013 by water monax 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
monax Posted November 28, 2013 Author Share Posted November 28, 2013 Thanks that make it clearer Link to comment Share on other sites More sharing options...
water Posted November 28, 2013 Share Posted November 28, 2013 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
KaFu Posted November 28, 2013 Share Posted November 28, 2013 Case 1, 7 .. 79 > Case 1, 7 to 79 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
water Posted November 28, 2013 Share Posted November 28, 2013 The OP doesn't want all numbers from 7 to 79, just the multiples of 6. I was just to lazy to type all numbers My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
KaFu Posted November 28, 2013 Share Posted November 28, 2013 Oh, I see, did not read the OPs question properly, sorry ... For $ii = 1 To 81 If Not Mod($ii - 1, 6) Then ConsoleWrite("+" & @TAB & $ii & @CRLF) Else ConsoleWrite("-" & @TAB & $ii & @CRLF) EndIf Next monax 1 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
monax Posted November 29, 2013 Author Share Posted November 29, 2013 I didnt know about the Mod function before, thats perfect for the job Anyway since the numbers for switch syntax are not a lot (in this case), I will use switch, but Mod will be a nice function for other things. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now