For each cycle

Propose new features and changes
jekko1976
Posts: 36
Joined: 10 Oct 2014, 07:03

For each cycle

26 Apr 2018, 14:36

Wouldn't be cool to add the for each cycle, like php, to our beloved autohotkey?

Bye
swagfag
Posts: 1075
Joined: 11 Jan 2017, 17:59

Re: For each cycle

26 Apr 2018, 17:07

what do u mean? there is a for each already
jekko1976
Posts: 36
Joined: 10 Oct 2014, 07:03

Re: For each cycle

27 Apr 2018, 02:19

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.

Code: [Select all] [Download] GeSHi © Codebox Plus

Array := []
Array[1] :=how
Array[2] :=are
Array[3] :=you
For each element in Array
{
MsgBox, element
}


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
User avatar
nnnik
Posts: 3184
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: For each cycle

27 Apr 2018, 02:46

Code: [Select all] [Download] GeSHi © Codebox Plus

Array := []
Array[1] :=how
Array[2] :=are
Array[3] :=you
For each, element in Array
{
MsgBox % element
}
Recommends AHK Studio
just me
Posts: 5456
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: For each cycle

27 Apr 2018, 04:00

Code: [Select all] [Download] GeSHi © Codebox Plus

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
}
jekko1976
Posts: 36
Joined: 10 Oct 2014, 07:03

Re: For each cycle

27 Apr 2018, 04:37

ah, with the comma it works.
Ok, thank you very much
guest3456
Posts: 2392
Joined: 09 Oct 2013, 10:31

Re: For each cycle

01 May 2018, 10:13

jekko1976 wrote:ah, with the comma it works.
Ok, thank you very much


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 want

https://autohotkey.com/docs/commands/For.htm

Code: [Select all] [Download] GeSHi © Codebox Plus

Array := []
Array[1] := "how"
Array[2] := "are"
Array[3] := "you"
For each, element in Array
{
MsgBox %each% : %element%
}


Code: [Select all] [Download] GeSHi © Codebox Plus

Array := []
Array[1] := "how"
Array[2] := "are"
Array[3] := "you"
For foo, bar in Array
{
MsgBox %foo% : %bar%
}


Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 1 guest