AllTheTimeWorld.com

csharp booleanif Statements

if Statements

An if statement executes a group of statements only if certain conditions are true

if Statements

An if statement executes a group of statements only if certain conditions are true

The if Statement

Sometimes a programmer would like a statement, or group of statements to execute only if certain conditions are true.
There may be a different statement, or group of statements that are to be executed when the condition is false.
In this example, the checked property of a checkbox is used. A Boolean variable or property doesn't need to be compared to anything, it already has a value of true or false.

This is the format for the if statement:

if( Boolean expression)
{
    statements;
}
else
{
    statements;
}

If the Boolean expression is true, all of the statements inside the first set of curly braces are executed.
The else section is optional;. if there are no statements to execute when the Boolean expression is false, you may leave out the else section.