will the else statement remains same for all if statements or they will have different else statements for different if statemen | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

will the else statement remains same for all if statements or they will have different else statements for different if statemen

15th Oct 2016, 3:59 PM
Rajat Semwal
Rajat Semwal - avatar
3 Answers
+ 1
The answer is: different else statement for different if statement
3rd Jul 2020, 6:01 PM
Crillos
0
It will be helpful if you can post a sample code explaining your problem. This is how conditional statements work in c++ (and most of the other programming languages). Each conditional check has one of two values, "true" or "false". So for each if statement you can define what to do if it's evaluated to true, and if it's evaluated to false. e.g. if(i==0) { i++ } else { i--; } But if you want you can omit the else part. Then it will proceed to the next executable line. Every "else" clause has single matching "if" clause. You cannot share an "else" clause with multiple "if" clauses.
16th Oct 2016, 6:32 AM
Sumudu
Sumudu - avatar
0
Yes ,I hope you can share multiple "if" with a single "else". here is an example: if (score >= 90){ grade = 'A'; } if (score >= 80){ grade = 'B'; } if (score >= 70){ grade = 'C'; } if (score >= 60){ grade = 'D'; } else { grade = ‘F’; }
9th Jul 2020, 6:36 AM
rakshitha akkireddy
rakshitha akkireddy - avatar