Code: Select all
Loop
{
If A_Index = 10
Break
}
...
Return
Loop
{
If A_Index = 10
Return
}
...
Return
Code: Select all
Loop
{
If A_Index = 10
Break
}
...
Return
Loop
{
If A_Index = 10
Return
}
...
Return
Code: Select all
Loop
{
If A_Index = 10
Break
}
MsgBox, This gets executed
Return
Code: Select all
Loop
{
If A_Index = 10
Return
}
MsgBox, This does not get executed
Return
It seems I didn't write the question specifically.boiler wrote: ↑23 Oct 2021, 22:01It's not a matter of stability. It's a matter of how the code is supposed to flow when exiting the loop. You would choose break or return to do very specific things. You would use break to have it continue executing the commands below the loop, and you would use return to return back to where it was called from (or to exit the script if it was not called by something).
Examples:Code: Select all
Loop { If A_Index = 10 Break } MsgBox, This gets executed Return
Code: Select all
Loop { If A_Index = 10 Return } MsgBox, This does not get executed Return
Code: Select all
Loop
{
IfExist,A.exe
{
LabelSuspend = 1
break
}
}
If LabelSuspend = 1
Return
Loop
{
IfExist,A.exe
{
Return
}
}
Return
It does not. When you return from directly inside a loop, the script doesn't think that you're still inside the loop for any reason.whynotregister wrote: ↑ Because I was wondering if using return instead of break > return to immediately exit the loop could cause goto-like instability.
thank you for answerboiler wrote: ↑23 Oct 2021, 22:15It does not. When you return from directly inside a loop, the script doesn't think that you're still inside the loop for any reason.whynotregister wrote: ↑ Because I was wondering if using return instead of break > return to immediately exit the loop could cause goto-like instability.