Conditional Statements



Conditional Statements


In C Program we use a conditions when there is no condition in the statements.  When put a condition on a block of Statement in the C language then the result of the statement is changed by the condition. This process is referred as decision making In C and the decision-making statements are also called as control statements.


In C programming there is possible two conditional statement:

 If Statement:- If statement is responsible for modifying the flow of execution of a program. This statement is always used with a condition.

if(condition){

  statement(s)




If - else statement:- If the condition is true in the if else statement then it executes the statement of it. If the condition is false then the else statement executes.


if(condition){

 statement(s);

}else{

statement(s);










Switch Statements:- Switch case statement has expression and some cases related to it. The case which matches that expression or declare variable is printed in the output. If no case matches the expression then it will print the default statement in the output. You have to break after every statement that means it will print only the statement before it. If you do not break, then it will print both the first and the second statement. Do not break after the default case.



switch (expression)

{case value1 :statement1 ;

break;

case value2 :statement2 ;

break;

default :statement3 ;}


 continue statement:- Depending on the condition of the loops of the Continue Statement program, skip the middle statements and execute the subsequent statements.

continue;



GOTO:- goto to is the statement of C Programming. Labels are used in this.


There are two types of Goto Statement.

  • Forward

  • Backward


When the goto statement executes its next statement except for some statement, it is called Forward goto statement and goes to its previous label to execute any previous or executed statement again, it is called Backward goto statement.



Syntax for Forward

goto label ;

statement ;
-------------

label;


Syntax for Backward

label ;

statement ;

-----------

goto label ;




Post a Comment

0 Comments