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

Engg.... | 04:10 | | | Best Blogger Tips
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;
}


Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

12 comments:

  1. I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job .If anyone want to get php Developer Training in Chennai,
    Please visit Besanttechnology located at Chennai Velachery. Rated as No.1 Training Institutes in Chennai. besant technologies reviews | besant technologies reviews | besant technologies reviews

    ReplyDelete
  2. Very informative article.Thank you author for posting this kind of article .



    http://www.wikitechy.com/view-article/four-types-of-case-control-statements-in-c-language



    Both are really good,
    Cheers,
    Venkat

    ReplyDelete
  3. Really a good technical site,keep on writing good stuffs
    dot net training in chennai

    ReplyDelete
  4. Really good.In these interview tutorial used now my Jobs Career. We share Conditional control Statement reality program i'm understand I've to used this code my studied exam.
    Hadoop Training in Chennai | Selenium Training in Chennai

    ReplyDelete
  5. Java is high level programming language .Due to its stability and scalability, you can find Java on mobiles, desktops, large scale applications etc. Java is also gaining big in the field of Internet of Things (IoT).
    Java training center in chennai

    ReplyDelete
  6. The Spring Framework is a lightweight framework for developing Java enterprise applications. It provides high performing, easily testable and reusable code. Spring handles the infrastructure as the underlying framework so that you can focus on your application.Spring is modular in design, thereby making creation, handling and linking of individual components so much easier. Spring implements Model View Container(MVC) design pattern.
    spring mvc validation example

    ReplyDelete
  7. This is really good explanation on Control flow statement by using C and C++ language. Thanks for the article....

    Best AngularJS Training in Chennai

    ReplyDelete
  8. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.

    Cassandra Database Training in Chennai
    Cassandra Training in Chennai

    ReplyDelete
  9. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    health and safety courses in chennai

    ReplyDelete
  10. I really love the theme/design of your website. Do you ever run into any browser compatibility problems? A small number of my blog audience have complained about my site not working correctly in Explorer but looks great in Safari.
    safety courses in chennai

    ReplyDelete