IF:
The if statement selects a statement for execution
based on the value of a Boolean expression
1)Simple if
2) If Else If
3) Multiple Ifs
4) Nested ifs
5) Switch-case
Syntax:
Simple if:
If(condition)
{
Statement
}
Syntax for if else:
If(condition)
{ Statement
}
Else
{ Statement;
}
Example:
if
(flagCheck == true)
{ Console.WriteLine("The flag is
set to true.");
}
else
{ Console.WriteLine("The flag
is set to false.");
}
Syntax for Multiple
ifs:
If(condotion)
{ statement
}
If(condition)
{ Statement
}
Syntax for nested ifs:
If()
{
}
else if()
{ Statement
}
Syntax for Switch
case:-
Switch(“expression”)
{ Case exp1:
{ Statement
break;
}
Case exp2:
{ Statement
break;
default:
{
Statements } } } }
No comments:
Post a Comment