+ 2
What is if and else in program?
if(a%2==0) { cout<<"no is even."; } else cout<<"no is odd": here what is if and else. function any object etc.?
3 ответов
+ 8
'if' and 'else' are identifiers which tells the program to evaluate specified conditions.
+ 1
ok thanks
+ 1
if and else is using when you have more than 1 condition
example for your code in upper :
if a%=2
% is modulus and a is variable
so when you input 2, and finally a is 2, 2 modulus 2 = 0. then you can see that is even,
but if you input 3, and finally a is 3, 3 modulus 2 = 1. then you can see that is odd
and if you have more than 2 condition, its called "nested if"
example :
if fruits=mango
print "mango"
if "mango"
run=true
else if fruits=apple
print "apple"
else
print "no input"