Decision making using if statement
The if statement is a powerful decision making statement and is used to control the flow of execution of statements. It's a basically two way decision statement and is used in conjuction with an expression. It's syntax is:- "if(test expression)" It allows the computer to evaluate the expression first and then, depending on condition, it transfers the control to a particular statement. This point of program has two paths to follow,one for the true and other for false condition.As shown in figure:- Practical examples of if statement:- 1. if(bank balance is < 500) deposit money 2. if(room is dark) put on lights The if statement may be implemented in different forms depending on the complexity of conditions to be tested. The different forms of if statements are:- 1.Simple if statement 2.if....else statement 3.Nested if....else statement 4. else if ladder 1.Simple if statement. The general f...
Comments
Post a Comment