If Statements - How do they work - C# and VB

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

This may seem a very simple question to most people but just wanted to clear it up.

When program runs some code and comes to an IF statement where two (or more) boolean statements have to be true before it continues. If the first boolean statement is false, does the program continue to the ELSE statement, or does it still interrogate the second boolean statement.

Is it different in different languages, ie. C# and VB.

Thanks.
 
in c# at least when evaluating the if clause, if the program ever reaches a condition where it will fail/succeed no matter what happens in the remaining tests, it will then not evaluate those tests and proceed to into the if/else block as appropriate; this is know as short-circuit evaluation.

More details can be found here

akakjs
 
VB.NET does not behave in the same way as C# (described above) and will perform the subsequent tests within a condition regardless of whether the overall condition has been already satisfied by that point. However short-circuiting can be achieved with the AndAlso and OrElse operators.
 
Last edited:
Back
Top Bottom