CoNtrol StaTemEnts



Control statements: C++ provide us a way through which we can handle a situation and apply some logic on it according to requiring condition and these all are done by those statements called control or decision statements.




  Types of control statements. 
  • if -else statement
  • switch statement
  • for loop
  • while loop
  • do-while loop
Consider this program for if-else statement:



























syntax of if-else statement: 
if(condition)
{
statement;
}
else
{
statement;
}


this statement is used for comparing two numbers that 's why i consider two integer and then apply conditions over them.


switch statement: 
This statement is used for making case like structure and according to ANSCI C there is 257 cases are made only it is also called selection statement .


consider this program:





















    
syntax:
switch(input condition)
{
case 1:statement;break;
case 2:statement;break;
default:statement;break;
}


For loop: 
It is used for counting like arrangement eg 1,2,3,4.........so on.




In this program first of all  consider a integer i then  intialize the value of i then terminating condition occurring and at last incre/decre of i come in future .


syntax:
for(initialization condition;condition terminating;condition increment/decrement)


while statement
In while loop condition is first initialize then terminate condition and after that increment/decrement occurring.


syntax:
{
condition initialize;


while(condition terminate)
{
statement;
condition increment/decrement;
}








































 do-while statement:
         In this case first of all statement is executing after initializing the condition and                      then terminating condition occurring with while statement.
consider this program:





























syntax of do-while statement:
do
{
statement;
increment/decrement condition;
}
while(terminating condition);


Watch this video for understanding control statements.
video 2)