Re: Break, continue - allow expression mode
Posted: 01 Jul 2014, 21:10
+1 dah quote
Let's help each other out
https://www.autohotkey.com/boards/
This doesn't convince me, as it appears that it is possible to have multiple control flow-like statements in one line in v2:Coco wrote: Break is more like a control flow statement rather than a command. If it were one, I would expect this to work for v2, but nope, it doesn't...:Code: Select all
for k, v in ['ABC', 'DEF', 'GHI'] if (v == 'DEF'), break() ; Command(s) can be called using function syntax -> this throws an error
Code: Select all
a := 3, b := 4
for k, v in ['ABC', 'DEF', 'GHI']
if (v == 'DEF'), if(a == 3), if(b == 4), break
Code: Select all
a := 3, b := 4
for k, v in ['ABC', 'DEF', 'GHI']
if (v == 'DEF'), if(a == 3), if(b == 4), break, , found := true
All commands can now be called as functions, except for control flow statements
http://ahkscript.org/v2/v2-changes.htm
Yes. Lets differentiate between two things:Lexikos wrote:If, Else, Try and Finally can be followed by almost anything which can normally be used at the start of a line (because these statements are expected to be followed with an associated line or block of code). This is not true for all control flow statements. I think Coco's point was that it is a control flow statement, and therefore can't be called with function() syntax.All commands can now be called as functions, except for control flow statements
http://ahkscript.org/v2/v2-changes.htm
To continue the thought, if it is possible to have something (a command / other cf statement) to the right of the control flow statement, _why_ can't there be anything right to break (if it's a cf statement too). So now we can see that in this context, there are _two_ types of cf statements - the ones that can be followed with something and the ones that can't.Coco wrote:Break is more like a control flow statement [...]
Code: Select all
loop
{
K:=A_index
Break
}
Code: Select all
loop
Break,,K:=A_index
Code: Select all
for index, item in list {
} until item = input && found := index