Conditional Statements
1 If Statement
void main()
{
// If statement
if(condition c1)
{
// ...
}
else if(condition c2)
{
// ...
}
else if(condition c3)
{
// ...
}
// ... other else ifs
else if(condition cn)
{
// ...
}
// When conditions c1..cn fail
else
{
//..
}
}
2 Switch Statement
void main()
{
// Switch statement
switch (choice)
{
case 1:
// ...
break;
case 2:
// ...
break;
// ... other cases
case n:
// ...
break;
// When none of the cases is true
default:
// ...
break;
}
}
Last modified: Wednesday, 13 November 2024, 8:23 AM