The if and else statement

Asked By 0 points N/A Posted on -

My previous question was about break and continue and i forget to ask one more question that is tell me about if and else statement.why we use this and also the syntax

Best Answer by Ysaf Goal
Best Answer
Best Answer
Answered By 0 points N/A #123116

The if and else statement


The if and else statements can be considered as the decision making statements.In simple words its like daily life decisions,for example IF ALIC GOES TO THE PARTY THEN I LL GO ELSE I LL NOT GO.So in programming terms if the first condition is true then else statement ll not be executed.If first condition gets false then else condition ll be executed.

There is a simple C program to show how if and else statements works.




cout<<"this is the last value of the loop";


cout<<"this is not the last value of the loop";


Answered By 10 points N/A #123118

The if and else statement


These are two commands we give to computer and computer do some thing on this behalf. The if statement is used where the condition is dependent on if mean that if some thing happens then do this thing and else statement is used where you need to specify that if this thing does not happen then do some thing else. This is the basic thing in if and else statement. You need to use them on your demand. You can only use if statement or else statement and also you can use them together. You will be then able to get your result as you require. The thing here is the result you want form this statement the statement does not contain any result but if  you want to control a airplane then it does matter. You can even use it in a mouse where a click is for if statement and else is for another click. This is the basic thing you need to keep in mind.

Answered By 0 points N/A #123119

The if and else statement


If there are two conditions then we can use IF ELSE statements in the programming language. IF & ELSE statement is two most important & salient features in the C Programming Language. These two statements are used greatly in writing code in C programming language. Now I am giving a very simple example of these two statements in a few words.

Suppose you have to finish a work. You have two options to finish by hiring Michel Or John. Michel is demanding more money than John wants. But you choose that Michel does the work. Then the algorithm is like this;

IF(Michel Agree)
Prinf( Michel will finish the Job);
Prinf(John will work the Job);

Answered By 0 points N/A #123120

The if and else statement


Basically, if-else statement is condition-based statement. Whenever we want to take any action which is based on the outcomes of the given condition, (True or False) , then we need to use the if-else statement.

The syntax for this statement is as follows:


the statement  //  x1


the statement . // x2

If the condition in the syntax is true, then the x1 is executed and if the condition in the syntax is false then x2 is executed. Let us consider an example,

if (y>z)

printf ("the greater no is %d", y);  // x1


printf("the greater no is %d", z);  // x2

Here, if y is greater than z then x1 is executed, otherwise x2 will be executed.

As a whole, if-else statement is totally based on the condition given in the synatax.

Login/Register to Answer

Related Questions