For-Loop Remove Index and replace with Built In Variables

Propose new features and changes
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

For-Loop Remove Index and replace with Built In Variables

26 Aug 2017, 22:27

I think it's kind of redundant to have the Value and Key parameter in the command when AHK has built in variables for it anyway.
For example, instead of the syntax being like this:

Code: Select all

For Key [, Value] in Expression
{
	; Some Actions
}
Why not have the syntax like this:

Code: Select all

For (Array,Obj, or Expression) {
	MsgBox, % A_LoopFieldName " = " A_LoopField
}
I don't know, something along those lines. And maybe for backward comp, keep the old syntax available for use.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: For-Loop Remove Index and replace with Built In Variables

26 Aug 2017, 22:31

Ok I am too tired to code. I meant to use variables that are built into AHK, and use them for a "better" syntax of a For-Loop

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

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

Re: For-Loop Remove Index and replace with Built In Variables

26 Aug 2017, 23:30

Actually, you could make the opposite argument. To allow the Loop control flow statement to support custom variable names instead of A_Index and A_LoopField, or A_LoopFileFullPath.

The benefit would be that you could use the same variable names that you use in normal circumstances, both inside and outside of loops.

Anyhow as it is now, lines where you simply copy the variable contents over:
vTemp := A_LoopField
vPath := A_LoopFileFullPath
are not so bad.

The fact that the object loop allows custom variable names is a great advantage.

[EDIT:] However, if this were possible, to allow the use of certain 'A_' variables, that could make certain code reuse easier. Not that I would personally want to do this, or think it necessarily worth the cost of implementation.

Code: Select all

for A_Index, A_LoopField in oArray
	vOutput .= A_Index " " A_LoopField "`r`n"
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 50 guests