If-else statements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

If-else statements

Can someone show me a really simple example using if-else (with numbers for example)?

19th Mar 2019, 1:17 PM
M M
M M - avatar
3 Answers
+ 1
int x = 3; if (x == 3) { Console.WriteLine("x is three"); } else { Console.WriteLine("x is not equal to three"); } https://code.sololearn.com/cUpZ3Z79jL0S What is it you do not understand about if else statements ?
19th Mar 2019, 9:52 PM
sneeze
sneeze - avatar
+ 1
Thanks, I tried some codes with numbers and it worked, but, when I did the same but with string type, only problem was with part after "if"( where you have (x==3)). Can you please give me an example where x==3 is replaced with some word?
20th Mar 2019, 5:35 AM
M M
M M - avatar
+ 1
I have added string compare in my example. Spaces are ignored in c# so use as many as you like
20th Mar 2019, 5:59 AM
sneeze
sneeze - avatar