Sponsored Ad

Thursday, September 24, 2009

The if Statement in C#

For codicillary branching, C# inherits the C and C++ if...else construct. The syntax should be very easy for anyone who has done any programming with a procedural language.

if(condition)

statement;

  1. condition is a Boolean (that is, true or false) expression.
  2. If condition is true, then the statement is executed.
  3. If condition is false, then the statement is bypassed.
The complete anatomy of the if account is


if(condition)
statement;
else
statement;

statement;
The general form of the if using blocks of statements is


if(condition)
{
statement sequence
}
else
{
statement sequence
}

statement sequence
} if-else-if ladder. It looks like this:


if(condition)
statement;
else if(condition)
statement;
else if(condition)
statement;
.
.
.

else
statement;

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers