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/
Loop Parse Reverse
Re: Loop Parse Reverse
Although there is this for delimiter-separated lists (via StrSplit) and linear arrays (starting at 1) with no gaps:
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.
Code: Select all
oArray := ["a", "b", "c", "d", "e"]
Loop, % vIndex := oArray.Length()
MsgBox, % oArray[vIndex--]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Loop Parse Reverse
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.
Re: Loop Parse Reverse
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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Loop Parse Reverse
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.
At least you will notice this if you have a larger number of entries.
Recommends AHK Studio
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Loop Parse Reverse
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.
Re: Loop Parse Reverse
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.
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
Who is online
Users browsing this forum: No registered users and 86 guests