0
Why we are using if and if else statement. Can you answer me
5 Answers
+ 9
if you are cleaver then you will understand else you wont understand ..its that simple
observe following code
if(you are cleaver)
{
you will understand.
}
else
{
you wont understand.
}
more precisely
if("you are cleaver" is true)
{
"you will understand."
}
else
{
"you wont understand."
}
ie if condition specified inside parenthesis after keyword "if" is true then statement written inside ifs block ({}) is going to execute and if condition specified is false then statemets inside elses block({}) will execute.
+ 4
If else is for more than one choices
+ 2
Without if / if else statements, you only can execute instruction linearly... to make responsives programs, you need to choice to execute a certain part of code or another one, determining that choice by a condition ^^
So, very basic example, is if the code ask the user for a value, and accordind to this value, did a thing or another ;)
+ 1
We use if else when we only want one of the if, if else statements to execute
eg.
if (x == 1) {x++;}
else if (x == 2) {x--;} //only one can execute
if (x == 1) {x++;}
if (x == 2) {x--;} //both could execute
0
if statement is like a while loop but it works once when the condition is true ,,&&the else statement is for other conditions