Loop Parse Reverse

Propose new features and changes
guest3456
Posts: 2329
Joined: 09 Oct 2013, 10:31

Loop Parse Reverse

04 Apr 2018, 10:14

Wishing for a builtin way to traverse the loop backwards, perhaps adding an additional "R" parameter at the end of the param list

refs:
https://autohotkey.com/board/topic/7965 ... n-reverse/
https://autohotkey.com/board/topic/8118 ... backwards/

User avatar
jeeswg
Posts: 4575
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Loop Parse Reverse

04 Apr 2018, 10:31

Although there is this for delimiter-separated lists (via StrSplit) and linear arrays (starting at 1) with no gaps:

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

oArray := ["a", "b", "c", "d", "e"]
Loop, % vIndex := oArray.Length()
MsgBox, % oArray[vIndex--]

I would also very much welcome a way to loop through a linear/associative array in reverse. In particular, a way to safely delete keys during a for loop.
guest3456
Posts: 2329
Joined: 09 Oct 2013, 10:31

Re: Loop Parse Reverse

04 Apr 2018, 10:54

Would rather avoid having to StrSplit to create a separate array.

https://autohotkey.com/docs/commands/LoopParse.htm wrote:Parsing loops use less memory than StringSplit (since StringSplit creates a permanent pseudo-array) and in most cases they are easier to use.

User avatar
jeeswg
Posts: 4575
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Loop Parse Reverse

04 Apr 2018, 11:11

Fair point. Something like this would be especially useful for getting the last few lines/items in a massive list, a common request. Perhaps that's what you had in mind.
User avatar
nnnik
Posts: 2964
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Loop Parse Reverse

04 Apr 2018, 13:57

Essentially an inversed iterator. It's especially useful since using Loop and accessing the array inside is a whole lot more costly than using an enumerator.
At least you will notice this if you have a larger number of entries.
Recommends AHK Studio
User avatar
Masonjar13
Posts: 1347
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Loop Parse Reverse

04 Apr 2018, 17:04

This deviates slightly, but is related: why do a number of languages choose to use for-loops for objects, rather than the traditional C[++] for-loop? It allows for custom increment steps, making it inversable and generally more flexible. I personally think it's the best loop approach. I suppose that could probably be done with current syntax via a function, but it wouldn't be as fast, certainly.
User avatar
nnnik
Posts: 2964
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Loop Parse Reverse

04 Apr 2018, 17:36

Because it makes no sense.
Most of the objects in other languages have no integer keys - how do you plan to use a traditional C loop?
The final answer you will come to is always going to be the modern for loop going over an iterator.
I also believe that the traditional C++ loop is one of the best when it comes to procedural programming - however as soon as OOP comes into the play it is nothing but a shackle syntax wise.
Recommends AHK Studio

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 3 guests