What is the difference between including a ':' (colon) in a labeled break statement and not including the colon? The documentation seems to indicate that a colon is necessary but it seems to work the way I would expect only without a colon.
More specifically without a colon the following script works as I would expect
:test1 for ($ i= 1; $i -le 2; $i++) {
for ($j = 1; $j -le 2; $j++) {
for ($k = 1; $k -le 2; $k++) {
Write-Host "$i, $j, $k "
if ($i -eq 2) {
break test1
}
}
}
}
and outputs
1, 1, 1
1, 1, 2
1, 2, 1
1, 2, 2
2, 1, 1
But if I add a colon to the labeled break statement (change line 6 to break :test1) the script outputs
1, 1, 1
1, 1, 2
1, 2, 1
1, 2, 2
2, 1, 1
2, 2, 1
which I wouldn't expect. What is the difference between the scripts with and without a colon in the break statement?
Thanks, David