Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

C# - Control Statements


Control flow and program logic are of the most important parts of a programming language’s dynamic behavior. In this section, I’ll cover control flow in C#. Most of the condition and looping statements in C# comes from c and C++. Those who are familiar with java will recognize most of them, as well.

The if . . .else Statement 
The if . . .else statement is inherited from C and C++. The if . . .else statement is also known as a conditional statement. For example:
if (condition)
statement
else
statement

The if. . .section of the statement or statement block is executed when the condition is true; if it’s false, control goes to the else statement or statement block. You can have a nested if . . .else statement with one of more else blocks. 

Iterative Statement: do-while Loop

It is another repetitive control structure provided by C++. It is an exit control loop. It evaluates its test-expression after executing its loop body statements. A do-while loop always executes at least once.
The syntax of the do-while loop is
do
{
statement;
}
while ;

LEARN MORE>>

Iterative Statement : While Loop

The while loop.
As mentioned earlier, the while loop is an entry controlled loop. The syntax of a while loop is
while (condition) statement
and its function is simply to repeat statement while expression is true. While is a reserved word of C++; condition is a Boolean expression; and statement can be simple or compound statement.
For example, we are going to make a program to count down using a while loop: LEARN MORE>>

Iterative Statement : for Loop

For some programming objectives it is necessay to repeat a set of statements a number of times until a certain condition is fulfilled. In such situations iteration statements can be used. The iteration statements are also called loops or looping statements.
Parts of a loop
1. Initialization Expression.
2. Test Expression
3. Update Expressions
4. Body of the loop.
The for Loop
The for loop is a deterministic loop in the sense that the program knows inadvance how many times the loop is to be executed.
LEARN MORE>>