Conditional Control Statements of C and C++ Language Part-1

conditional statement

CONDITIONAL CONTROL STATEMENTS:
  • Conditional Control Statements involves performing a Logic Test. 
  • This Test results either a TRUE or FALSE.
Depending upon the truthness or falsity of the condition, the statememts to be executed is determined. After that, the control transfers to the statement in the program and start executing the statements. This is known as Conditional Execution.
In C four conditional control statements are widely used:
  1. If-statement
  2. If-else statement
  3. Nested-if-else statement
  4. Switch statement
Let us take all control statements one by one: 
 
 
If-Statement:
This is used to execute a statement or a collection of statements conditionally or you can say that it is used to execute only one action. It is called one way branching. Here the logical condition is tested which results either TRUE or FALSE. Syntax of if statement is

 if(condition) 
    {
 statement1;
    }
 
Where
Condition => is a logical expression that results in TRUE or FALSE.
Statement => a simple statement(single statement) or compound statement(collection of two or more statement).
Elxpanation: If the logical condition is TRUE then statement1 is executed and If the logical condition is FALSE then control transfers to the next executable statement.

If-Else Statement:
This is used to execute two statements alternatively. It is called a two way branching.The syntax of if-else statement is


 if(condition) 
     {
 statement1;
     }
 else
     {
 statement2;
     }

Explanation: If the logical condition is TRUE then statement1 is executed and If the logical condition is FALSE then control transfers to the next executable statement that is statement2.

Nested If-Else Statement:
It is used if there are more than two alternatives to select.The syntax of nested-if statement is


 if(condition1) 
{
 if(condition2) 
      {
 statement1;
      }
 else
     {
 statement2;
     }
 }
 else
    {
 statement3;
     }

Explanation: Statement1 is executed if condition1 and condition2 are TRUE. if condition1 is TRUE and condition2 is FALSE then statement2 is executed. if condition1 is FALSE then control transfer to the else part and statement3 is executed.



Switch Statement:
It provides a multiway branching. It allows user to select any one of the several alternatives, depending upon the value of an expression. The value of expression enclosed with in the parentheses. Depending upon the value of expression,the control is transferred to a particular case and statements executed according to the case value.The syntax of switch statement is


switch(expression)
{
case value1;
  statement1;
      break;

case value2;
   statement2;
      break;

case value3;
    statement3;
      break;

case default;
   statement n;
       break;
}


6 Responses to "Conditional Control Statements of C and C++ Language Part-1"

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag