Jump to content

Recommended Posts

Posted (edited)

I'm sure this has been asked before but again I don't really know how to search for this because I don't know what it would be called.

I was thinking that because we can do this:

For $var in $array
  ...
Next

Would it make a good feature request to ask for this:

For $var1 in $array1, $var2 in $array2, ...
  ...
Next

Or whatever the best syntax would be?

Edited by jaberwacky
Posted

Is your request limited to just For...In loops?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Posted

N-dimensional collection For loop?

What would that sugar bring that we don't already have (beyond saving few keystrokes)?

For $var1 In $collection1
    For $var2 In $collection2
...
    Next
Next

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

For $var1 In $collection1     
    For $var2 In $collection2 
        ...     
    Next 
Next

I think it's a little different from nested loops.  The inner loop will run through $collection2 on the first $var1, and then on the 2nd $var1 it owuld run through $collection2 again, repeat.

The idea I have is to have them both go through the collections at the same time.

Here is the difference in output in our snippets:

Local $array1[5] = [1, 2, 3, 4, 5]

Local $array2[5] = ['a', 'b,' 'c', 'd', 'e']

For $var1 in $array1, $var2 in $array2   
  ConsoleWrite($var1 & @TAB & $var2 & @CRLF)
Next
1 a
2 b
3 c
4 d
5 e
Local $collection1[5] = [1, 2, 3, 4, 5]

Local $collection2[5] = ['a', 'b,' 'c', 'd', 'e']

For $var1 In $collection1     
  For $var2 In $collection2
    ConsoleWrite($var1 & @TAB & $var2 & @CRLF)
  Next 
Next
1 a
1 b
1 c
1 d
1 e

2 a
2 b
2 c
2 d
2 e

3 a
3 b
3 c
3 d
3 e

4 a
4 b
4 c
4 d
4 e

5 a
5 b
5 c
5 d
5 e
Posted

Ha, you intended that to be a N-parallel collection For loop, then, or an inner join on implicit iterators.

That will need to solve the obvious pitfall of collections having different cardinalities:

Local $array1 = [1, 2, 3, 4, 5]

Local $array2 = ['a', 'b,' 'c', 'd']

For $var1 in $array1, $var2 in $array2   
  ConsoleWrite($var1 & @TAB & $var2 & @CRLF)
Next
1 a
2 b
3 c
4 d
what to do next? stop here or raise error or:
5 Null

Anyway I don't see much use for such a construct, but you certainly have something in mind.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

I'm not familiar with any language that actually allows parallel looping like that. I've seen pairs of objects being enumerated, but never objects from different collections at the same time.

Can you give me an example where you've seen this before?

Posted

The possibility of accessing a partial-dimensional sub-array as a first-class array by itself would be much more powerful and useful in many more situations than just sugar in a For loop:

Local $a[3][2][2] = [ _
    [ _
        [ "A_000", "A_001" ], _
        [ "A_010", "A_011" ] _
    ], _
    [ _
        [ "A_100", "A_101" ], _
        [ "A_110", "A_111" ] _
    ], _
    [ _
        [ "A_200", "A_201" ], _
        [ "A_210", "A_211" ] _
    ] _
]

Local $b = $a[1]    ; should be a 2D array
;
;   A_100   A_101
;
;   A_110   A_101

Local $c = $a[1][1] ; should be a 1D array
;
;   A_110   A_111
;

For $elem In $a[2][0]
    ConsoleWrite($elem[0] & ', ' & $elem[1] & @LF)
Next
;    A_200, A_201

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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
  • Recently Browsing   0 members

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