Tank wrote:I mean the point of break is to stop here not to stop here and do these other things first
returns point is to go back to where you came from. with functions to return with a value
Break is a command. Every command has parameters. Some of the parameters can be expressions. Expressions are evaluated before the command is called. From the point of view of how Autohotkey works, this is perfectly logical I'd say.
Coco wrote:It makes the code look more confusing
Perhaps the reasoning behind creating the forum thread will sort this out. This is what I originally wrote:
Code: Select all
obj := ["aaa", "bbb", "aaa", "ddd", "eee", "aaa"]
for each, val in obj, Count := 0, found := false {
if(val = "aaa")
Count++
if(Count = 3) {
result := val, found := true
break
}
}
MsgBox, % found
I wanted to shorten this up to:
Code: Select all
for each, val in result, Count := 0, found := false {
if(val = "aaa")
Count++
if(Count = 3)
break, , result := val, found := true
}
In this example,
break works as sort of a mini-
return from the Loop function and just like it is the case with
return,
break could _also_ evaluate an expression on the same line, before 'exiting'.
Break could be considered a
return that doesn't return a value, but that _does_ evaluate an expression before returning. I mean
break, similar to
return, makes the flow of execution jump to the 'address' where the end of the loop/function call was.
I'd consider the above to be more readable than doing all of the assignments inside of the if() statement:
Code: Select all
for each, val in obj, Count := 0, found := false {
if(val = "aaa")
Count++
if(Count = 3 && (1, result := val, found := true) )
break
}