[Idea:] Wish to introduce Until{ }

Discuss the future of the AutoHotkey language
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[Idea:] Wish to introduce Until{ }

23 Jan 2024, 06:54

Wish to introduce Until{}. It generally has the below usages:

[Code1:]

Code: Select all

arr:=['John','Smith','Micheara']
loop{
	if arr[A_Index]=='David'{
		MsgBox('I found David!')
		break
	}
}Until A_index>=3{
	MsgBox('I can not find David!')
}
Or [Code2:]

Code: Select all

arr:=['John','Smith','Micheara']
for x in arr{
	if x=='David'{
		MsgBox('I found David!')
		break
	}
}Until{
	MsgBox('I can not find David!')
}
The Until block will be executed as long as the loop is not terminated by break , GoTo or continue 2.
Last edited by V2User on 23 Jan 2024, 21:55, edited 1 time in total.
Descolada
Posts: 1141
Joined: 23 Dec 2021, 02:30

Re: [Idea:] Wish to introduce Until{ }

23 Jan 2024, 08:18

for..until is already reserved:

Code: Select all

#Requires AutoHotkey v2

arr:=['John','Smith','Micheara']
for x in arr{
	if x=='Smith'{
		MsgBox('I found Smith!')
		break
	}
} until (x=='John')
MsgBox('I found John!')
I do wish that for...else would apply not for loops without any iterations, but for loops that make it to the end without breaking: that is, the same behavior as your example. That would break backwards compatibility though :(

I don't think I've ever had the need for Loop..Until{}. It might be a rare good use-case for GoTo:

Code: Select all

arr:=['John','Smith','Micheara']
loop{
	if arr[A_Index]=='David'{
		MsgBox('I found David!')
		goto Common
	}
}Until A_index>=3
MsgBox('I can not found David!')
Common:
MsgBox('After finding or not finding')

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 46 guests