Changes

Jump to: navigation, search

C Sharp Flow Control with if and else

5 bytes added, 18:17, 15 January 2008
Using ''if'' to Make Decisions
In previous chapters the ''if'' statement has been used in some examples. In this chapter of [[C Sharp Essentials|C# Essentials]] we are going to look at the ''if'' statements in a little more details.
== Using ''if'' to Statements Make Decisions ==
The ''if'' statement is perhaps the most basic of flow control options available to the C# programmer. Programmers who are familiar with C, C++ or Java will immediately be comfortable using C# ''if'' statements.
}
Essentially if the ''boolean expression'' evaluates to ''true'' (see [[C Sharp Operators and ExpressionExpressions|C# Operators and Expressions]] for more details of this type of logic) then the code in the body of the statement is executed. The body of the statement is enclosed in braces ({}). If, on the other hand, the expression evaluates to ''false'' the code in the body of the statement is skipped.
For example, if a decision needs to be made depending on whether one value is greater than another:

Navigation menu