Constrcuts are used for specific purpose ,like if you want to include statemtnts like ,the number is greater or number is b greater or you can say ,if you want to check this i good or that is good or this is bad and that is good like statements .
Constructs are of two main types :
Conditional Constructs
Loop Constructs
Conditional Constructs are used when you specify conditions in you C Program .
They are :
if...else
switch...case
Syntax for if...else :-
if(condition)
{
statement to be executed;
}
else
{
statement to be executed;
}
Syntax for switch...case :-
switch(variable/condition)
{
case 1:
statement to be executed;
break;
case 2:
statement to be executed;
break;
.
.
.
.
.
default:
statement to be executed;
break;
}
*break statement is used to terminate the case statement and move the compiler to the outer area of the construct or to the given statement.
*default is used for an additional case to be executed ,in case of any unexpected condition occurs .
Loop Constructs are used if you want to repeat/ Iterate the program or a specified condition for several times .
They are :-
while loop
do..while loop
for loop
Syntax for while loop :-
while(Condition)
{
statement to be executed;
}
Syntax for do...while loop :-
do
{
statement to be executed;
}
while(Condition)
Difference between while loop & do...while loop :
while loop & do..while loop are almost same ,but the only major difference is that do..while loop checks the condition after the execution of body .
Syntax for for loop :-
for(Initializing; condition; Increment /Decrements )
{
statement to be executed;
}
the first stage in for loop is initializing the variable ,then condition to be checked ,the what will happen if the specify given condition is true ,increment or Decrements .
Some Operators for Constructs :
Arithmetic Operators
(+ ,- ,* ,/ ,%)
+ is used for addition
- is used for difference
* is used for multiplication
/ is used for division
% is used to find out remainder
Logical Operators
(&&, ||, !)
&& is AND Operator ,used to find out the whole condition is true or false
|| is OR Operator ,used to find out any condition is true or false
! is NOT Operator ,used to find out or you can say define Negative Result
Unary Operators
(++, --)
++ used to increment the value of any variable or an operand by 1
-- used to decrements the value of any variable or an operand by 1
also applied on single operands .
Comparison Operators
(>, <, >= ,<= ,==, !=)
> is greater than
< is less than
>= is greater than equal to
<= is less than equal to
== equal equal to
!= not equal to
and many more ...
Constructs are of two main types :
Conditional Constructs
Loop Constructs
Conditional Constructs are used when you specify conditions in you C Program .
They are :
if...else
switch...case
Syntax for if...else :-
if(condition)
{
statement to be executed;
}
else
{
statement to be executed;
}
Syntax for switch...case :-
switch(variable/condition)
{
case 1:
statement to be executed;
break;
case 2:
statement to be executed;
break;
.
.
.
.
.
default:
statement to be executed;
break;
}
*break statement is used to terminate the case statement and move the compiler to the outer area of the construct or to the given statement.
*default is used for an additional case to be executed ,in case of any unexpected condition occurs .
Loop Constructs are used if you want to repeat/ Iterate the program or a specified condition for several times .
They are :-
while loop
do..while loop
for loop
Syntax for while loop :-
while(Condition)
{
statement to be executed;
}
Syntax for do...while loop :-
do
{
statement to be executed;
}
while(Condition)
Difference between while loop & do...while loop :
while loop & do..while loop are almost same ,but the only major difference is that do..while loop checks the condition after the execution of body .
Syntax for for loop :-
for(Initializing; condition; Increment /Decrements )
{
statement to be executed;
}
the first stage in for loop is initializing the variable ,then condition to be checked ,the what will happen if the specify given condition is true ,increment or Decrements .
Some Operators for Constructs :
Arithmetic Operators
(+ ,- ,* ,/ ,%)
+ is used for addition
- is used for difference
* is used for multiplication
/ is used for division
% is used to find out remainder
Logical Operators
(&&, ||, !)
&& is AND Operator ,used to find out the whole condition is true or false
|| is OR Operator ,used to find out any condition is true or false
! is NOT Operator ,used to find out or you can say define Negative Result
Unary Operators
(++, --)
++ used to increment the value of any variable or an operand by 1
-- used to decrements the value of any variable or an operand by 1
also applied on single operands .
Comparison Operators
(>, <, >= ,<= ,==, !=)
> is greater than
< is less than
>= is greater than equal to
<= is less than equal to
== equal equal to
!= not equal to
and many more ...
No comments:
Post a Comment