What is the difference between:
if (expr1) {stmt}
else if (expr2) {stmt}
else if (expr3) {stmt}
else {stmt}
And the same code block written as:
if (expr1) {stmt}
if (expr2) {stmt}
if (expr3) {stmt}
else {stmt}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the first one, each block of statements is mutually exclusive; the structure guarantees that exactly one of them will get executed.
This is not true for the second one. Consider:
If
a == 2, then two of the blocks will get executed.