Sagarmantha Prema
6 years ago
Conditional constructs are used to control the flow of program . conditional constructs allow the flow selective execution of statements , depending on the value of the expressions associated with them. The comparison operators are required for evaluating the conditions . various conditional constructs are :
1. if....else construct.
2. switch... case construct.
if...else conditional construct is followed by a logical expression where data is compared and a decision is made on the basis of the result of the comparison. syntax is
int n1=5;
int n2=6;
int n3=7;
if(n1>n2)
if(n1>n3)
{
Console.WriteLine("Number 1 is great");
}
else
{
Console.WriteLine("number 3 is great");
}
else if(n2>n3)
{
Console.WriteLine("number 2 is great");
}
else
{
Console.WriteLine("number 3 is great");
}
switch(variable name)
{
case option: statement;
break;
case option: statement;
break;
default: statement;
}
Labels: C# Programming