Why we are using if and if else statement. Can you answer me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why we are using if and if else statement. Can you answer me

30th Dec 2016, 2:05 PM
Anna Ash867
Anna Ash867 - avatar
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.
10th Feb 2017, 11:05 AM
Hardik Raut
Hardik Raut - avatar
+ 4
If else is for more than one choices
30th Dec 2016, 2:20 PM
Wilson Bol
Wilson Bol - avatar
+ 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 ;)
30th Dec 2016, 4:10 PM
visph
visph - avatar
+ 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
30th Dec 2016, 2:07 PM
Alex Matthews
Alex Matthews - avatar
0
if statement is like a while loop but it works once when the condition is true ,,&&the else statement is for other conditions
30th Dec 2016, 2:55 PM
Jamal Al-kelani
Jamal Al-kelani - avatar