You have no loop, no
switch
- so there is nothing for a
break
to do.
break
works in one of two ways:
1) Inside a loop (
for
,
foreach
,
while
, or
do
) the
break
statement immediately exits the current loop - and only the current, it will not exit the outer loop of a nested pair:
foreach (string s in myList)
{
foreach (char c in s)
{
if (c == "x")
{
break;
}
...
}
...
}
2) When used inside the
case
block of a
switch
statement, it exits the
switch
immediately.
case
blocks must end with a
break
,
return
, or
throw
They have nothing to do in an
if...else
statement, so you get a compilation error.