Conditional Statement
Learn the conditional statement in C#.
The most commonly used conditional statement in C# is the if
statement. It contains a conditional expression and a true branch, and it may contain a false branch. The true branch is executed when the conditional expression is true. The false branch, if present, is executed when the conditional expression is false. The following program demonstrates the use of the conditional statement.
Note: The
true
branch of theif
statement starts the execution after the starting brace{
and executes all the statements until the ending brace}
.
Syntax
if (conditional statement) // no semicolon here
{
// execution starts from here if the conditional statement is true
//until here
}
else
{
//if the true branch is not executed then this part of the code is executed
//until here
}
Get hands-on with 1200+ tech skills courses.