What is conditional branching

What is conditional branching

language some statements are made, which decide on the basis of condition, which statement to execute and which not, such type of statements are called conditional branching statements. 

Example : -  if ,if- else...
   

If Statement  If statement has two parts.  General if statement and if - else statement  In 'C' language, these are called control or decision making statements.  Computer first test expression in the If statement  Tests, then based on his veracity, he proceeds by selecting one of the two parts.  In this way it basically resorts to the two-way method.  The statement is used as follows  

      If (test expression) 
Normally in the if statement, the computer examines the tet expression or condition starting with if, if it is true then it goes to statement_block and marks the result is true, if it is false then leaving it to test the other. Its flowchart is shown as Ni Mento 
What is conditional branching
The common if statement in 'C' language is presented as follows. 

If (test expression) 
  Statement_block
Statement_next; 
       In this way statement block can contain a group of one or more statements. Thus in normal if statement, when the result of the condition is true, then all the statements of "statement_block 'will be executed. If the condition is false, the computer goes ahead leaving' statement_block 'and executes' statement_next '. If statement_block' If there is only one statement, then there is no need for curly basis. 

Example – 

main ( )
 int I;
Printf ("Enter any number : '');

Scand("%d'' , &I);i

if(i ==100 P

Printf ("\n Number is 100'');(

Printf"\n Try again...''); 


In the above example, if 100 is inputted then the computer will say "Number is 100". If the condition is false, only the last printin statement will be executed if the input is not 100. 

If- else Statement – if ... else statement is an extended form of if statement.  In this, if the condition is true or false, a statement or group of several statements will be executed.  It is usually presented in the following way 
if (test expression) 
{
Statement_block;

}

else

                      Statement_block; 

Statement_next; 

 

Its flowchart is given below. If the result of condition in this is true, then statement_blocki! Will be executive Except statement_block2, the computer will start analyzing the statement_next. If the condition is false, statement_block2 will be executed except for statement_block1. In any case, both blocks will never be executed. The following is an example of if .... else statement 
What is conditional branching
main (  )
{
 int I, n; 
 Printf("\n Enter any number:'')
 Scanf ("%'',&n);
 if (n<=100 &&n>=60)
      Printf ("\n Good, you are pass '');
else
      Printf("\n Sorry, you are fail");
      /*end of if ...else statement*/
} /* end of the program */ 


Post a Comment

1 Comments

Please give your suggestions in comments.