C#.Net Flow Control
Flow control can be categorized into 3 categories:
1. Selection Statements: Selection statements select one of a number of possible statements for execution based on the value of a controlling expression. Selection statements are of 2 types:
if statement: if statement selects a statement for execution based on the condition specified.
Switch statement: Switch statement executes the statements that are associated with the value of the controlling expression.
2. Iterations or Loops: Iterations are used to repeate execution of a statement or a set of statements. There are 4 types of Iterations:
For loop: Use to perform iteration i.e. repeat a block of instructions a given number of times.
While loop: Use to conditionally execute a set of statements zero or more time.
Do Loop: Use to conditionally execute a set of statements one or more time.
Foreach loop : Foreach loop is used to iterate through the collection to get the desired information.
3. Jumping Statements: Jumping statements are used to unconditionally transfer the control or it may transfer control out of a block. Jumping statements are of 3 types:
a. Break statement: Break statement exits the nearest enclosing switch, while, do, for or foreach loop.
b. Continue statement: Skips all the statements which are mentioned below continue keyword. Continue keyword is used inside a loop only.
c. Goto statement: The goto statement transfers the program control directly to a labeled statement.