What are control statements in C#?

CsharpProgrammingServer Side Programming

The flow of program control is specified by control statements in C#. It includes the following −

if statement

An if statement consists of a boolean expression followed by one or more statements.

The following is the syntax −

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
}

if-else statement

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

The following is the syntax −

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
} else {
   /* statement(s) will execute if the boolean expression is false */
}

for loop

It executes a sequence of statements multiple times and abbreviates the code that manages the loop variable.

The following is the syntax −

for ( init; condition; increment ) {
   statement(s);
}

while loop

It repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body.

The following is the syntax −

while(condition) {
   statement(s);
}

do…while loop

It is similar to a while statement, except that it tests the condition at the end of the loop body.

The following is the syntax −

do {
   statement(s);
} while( condition );
raja
Published on 06-Aug-2018 07:34:15
Advertisements