Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are, Simple if statement if….else statement Nested if….else statement Using else if statement Syntax if(expression1) { statement block1; } else if(expression2) { statement block2; } else if(expression3 ) { statement block3; } else { default statement; } The expression is tested from the top(of the ladder) to downwards. As soon as a true condition is found, the statement associated with it is executed. Example is shown below :: #include <stdio.h> #include<conio.h> void main( ) { int a; clrscr();…
-
-
Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are, Simple if statement if….else statement Nested if….else statement Using else if statement Syntax if( expression ) { if( expression1 ) { statement block1; } else { statement block2; } } else { statement block3; } If the expression is false then block3 will be executed, and if expression is true then again expression1 is evaluated, if it is true then block1 is executed, and if false then block2 will be executed. Example is shown below :: #include<stdio.h>…
-
Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are, Simple if statement if….else statement Nested if….else statement Using else if statement Syntax if(expression) { //Inside if Statement Are Executed } else { //Inside else Statement Are Executed } //Outside if...else block Statement Are Executed Here, if the expression is true then if block statements are executed and after it directly outside if…else block statements are executed, otherwise else block statements are executed and after it directly outside if…else block statements are executed. It means if expression…
-
Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are, Simple if statement if….else statement Nested if….else statement Using else if statement Syntax if(expression) { //Inside Statement Are Executed } //Outside Statement Are Executed Here, If the expression evaluated as true then inside statements are executed, otherwise outside statements are executed. If the if block has only one statement then there is no need to put curly braces {}, but if the if block has more then one statement then it must put curly braces. Example is…