tags:

views:

42

answers:

3

hello

how can i break out of an if statement?

exit only works for "for", "sub" ,...

thanks in advance

A: 

There isn't such an equivalent but you should't really need to with an If statement. You might want to look into using Select Case (VB) or Switch (C#) statements.

Radu
+1  A: 

In VB.net:

if i > 0 then
   do stuff here!
end if

In C#:

if (i > 0)
{
  do stuff here!
}

You can't 'break out' of an if statement. If you are attempting this, your logic is wrong and you are approaching it from the wrong angle.

An example of what you are trying to achieve would help clarify, but I suspect you are structuring it incorrectly.

Tom Gullen
A: 

In C# .NET:

if (x > y) 
{
    if (x > z) 
    {
        return;
    }

    Console.Writeline("cool");
}

Or you could use the goto statement.

thelost