Wouldn't be cool to add the for each cycle, like php, to our beloved autohotkey?
Bye
For each cycle
Re: For each cycle
what do u mean? there is a for each already
Re: For each cycle
i'm not sure about that
For sure there are almost 35 way different to obtain a Foreach cycle but, AFAIK the literal Foreach doesn't exist.
this code does not compile.
Anyway it's not necessary, of course. It could be useful for who came by php, nothing more.
Google told me that the case has been discussed many years ago
https://autohotkey.com/boards/viewtopic.php?t=4259
For sure there are almost 35 way different to obtain a Foreach cycle but, AFAIK the literal Foreach doesn't exist.
Code: Select all
Array := []
Array[1] :=how
Array[2] :=are
Array[3] :=you
For each element in Array
{
MsgBox, element
}
Anyway it's not necessary, of course. It could be useful for who came by php, nothing more.
Google told me that the case has been discussed many years ago
https://autohotkey.com/boards/viewtopic.php?t=4259
Re: For each cycle
Code: Select all
Array := []
Array[1] :=how
Array[2] :=are
Array[3] :=you
For each, element in Array
{
MsgBox % element
}
Recommends AHK Studio
Re: For each cycle
Code: Select all
Array := []
Array[1] := "how" ; if it shall be a literal string
Array[2] := "are"
Array[3] := "you"
For each, element in Array
{
MsgBox %element% ; if it shall be a variable reference
}
Re: For each cycle
ah, with the comma it works.
Ok, thank you very much
Ok, thank you very much
Re: For each cycle
realize its just a trick, the syntax is for key,val in object, you are just giving the 'key' variable the name 'each' since you don't care about the 1,2,3 indexes in your array. you can name them whatever you wantjekko1976 wrote:ah, with the comma it works.
Ok, thank you very much
https://autohotkey.com/docs/commands/For.htm
Code: Select all
Array := []
Array[1] := "how"
Array[2] := "are"
Array[3] := "you"
For each, element in Array
{
MsgBox %each% : %element%
}
Code: Select all
Array := []
Array[1] := "how"
Array[2] := "are"
Array[3] := "you"
For foo, bar in Array
{
MsgBox %foo% : %bar%
}
Who is online
Users browsing this forum: No registered users and 25 guests