C and C++ Control Structure Syntax of conditional and Looping statements

conditional and Looping statements-if,else,while, do- while, for 

syntax of if

----------------------

if(condition)
{
statement;
}

syntax of if else

-------------------
if(condition)
{
true_statement;
}
else
{
false_statement;
}

syntax of else if

-----------------------------
if(condition-1)
{
statement-1;
}
else if(condition-2)
{
statement-2;
}
else if(condition-3)
{
statement-3;
}
-
-
-
-
else
{
false_statement;
}

syntax of nested if

---------------------------------

if(condition-1)
{
if(condition-2)
{
true_statement;
}
}

syntax of switch

------------------------------
switch(expression)
{
case variable(int or char)1:statement-1;break;
case variable(int or char)2:statement-2;break;
case variable(int or char)3:statement-3;break;
default variable1:statement;break;
}

syntax of while

---------------------------
initialization;
while(condition)
{
statement;
inc/dec(++/--);
}

syntax of do while

-------------------------------
initialization;
do
{
statement;
inc/dec(++/--);
}
while(condition);

syntax of for

--------------------------
for(initialization;condition;inc/dec(++/--)
{
statement;
}


0 Comments