+ 1

what is the function and how and when should I use the if-else statement.. Any help please

17th Sep 2016, 3:05 PM
Richmond Kwarteng
Richmond Kwarteng - avatar
2 Antworten
+ 4
when handling a condition or e.g. user input that has 2 possibilities if(input>0){ /* some operations e.g. return 3/input; */ } else {/*print error or something like that can't devide by zero return null; */ }
18th Sep 2016, 12:32 AM
Ahmad Samy
Ahmad Samy - avatar
0
whenever there is a condition where there are two kind of output or say two possibilities .. for eg while writing a function for voting...you can vote only if you are above 18 else you cannot vote as you donot meet the minimum age for voting. so here you can have either of two outputs .. 1) you are allowed 2) you are not so in this case you can use if else statement . if (age>18) { // print allowed Console.Write("you are allowed"); } else { //print not allowed Console.Write("you are not alloed"); }
20th Sep 2016, 5:04 PM
Laze Hang
Laze Hang - avatar