Syntax
Simple if
if( Condition )
{
//code if the above condition is true.
}
if...else
if( Condition )
{
//code if the above condition is true.
}
else
{
//code if the above condition is false.
}
if...else ladder
if( Condition 1 )
{
//code if the above condition 1 is true.
}
else
{
if( Condition 2 )
{
//code if the above condition 2 is true.
}
else
{
// some code if the above condition 2 is false.
}
}
Nested if...else
if( Condition 1 )
{
if( Condition 2 )
{
//code if the above condition 2 is true.
}
else
{
//code if the above condition 2 is false.
}
}
else
{
if( Condition 3)
{
//code if the above condition 3 is true.
}
else
{
//code if the above condition 3 is false.
}
}
switch...case
switch ( expression )
{
case constant1:
//statements
break;
case constant2:
//statements
break;
.
.
.
case constantn:
//statements
break;
default:
//default statements
}
while
while ( condition )
{
//body of the while if the above condition is true
}
for
for ( initialization; condition; update_statement )
{
//body of for if the above condition is true
}
do...while
do
{
//body of do...while
}while ( condition );
go to
use 1:
goto label;
//code to skip
label:
use 2:
label:
//code to iterate
goto label;
Drafted on 🌏 by,
4 j aavshe?
ReplyDelete