This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Overview
Download & View Module 12 - Windows Forms as PDF for free.
Statements are the smallest unit of execution in C# programs. They can be grouped into sequences using curly braces. These are called Compound Statements or Blocks. A compound statement can be used in place of simple statement.
C# provides variety of statements. Most of the statements are similar to C,C++,Java.
The statements in C# can be categorized as:
Selection Statements
Iteration Statements
Jump Statements
Selection Statements
Selection Statements selects one of a number of possible statements for execution based on the value of a controlling expression.
A selection statement can be:
If Statement
Switch Statement
If Statement
The If statement selects a statement for execution based on the value of a Boolean expression.
Syntax:-
If(condition 1) statement_1 Else statement_2
Nested If
The If statement may be nested to many levels. This means If statement may contain another If statement.
Switch Statement A switch…case statement executes as follows: The switch expression is evaluated first and acts as the control of execution. If the value of the case label matches the switch expression, then the statements following it are executed. A label in a case is a fixed value. If no label matches the value of the switch expression, then the statements following the default label are executed. If there is no match and there is no default label then control is transferred to the end of the switch statement.