You can decide yourself which statements you want to execute and which statements you want to skip in your program. This process is called decision making.
Most decision making is done on the basis of a condition. When a particular condition occurs, you can execute the statements you want. For this, you use some built in statements. Because these statements work with conditions, they are also called conditional statements. And these statements control execution in the program, so they are also called control statements.
Read Also:
Before getting to know about these statements, let us try it with an example.
Most decision making is done on the basis of a condition. When a particular condition occurs, you can execute the statements you want. For this, you use some built in statements. Because these statements work with conditions, they are also called conditional statements. And these statements control execution in the program, so they are also called control statements.
Read Also:
Before getting to know about these statements, let us try it with an example.
Suppose you want to print the marks of any two students whose marks is more.
See the program given below:
1. If Statement:-
If statement is a control statement that test a particular condition. In these types of statements, if evaluated condition comes out to be true, then statement-block will be exicuted. Otherwise, the given set of action are ignored. The general syntex of a simple if statement is:The 'statement-block' may be a single statement or a group of statement. If the test expression is true, the statement-block will be executed; otherwise the statement-block will be skipped and the execution will jump to the statement-x. When the condition is true both the statement-block and the statement- x are executed in sequence.
2. If-else Statement:-
The if-else statement is an extension of the simple if statement. In these type of statements, when condition is true a group of statements are executed. If the condition become false, then else part will be executed.The general Syntex of if-else statement is:
2 Comments
Good work
ReplyDeleteNice artical
ReplyDelete