Consider that you have 2 different variables A and B. I have come up with the following case:
if (condition about A) {
// do something...
} else if (condition about B) {
// do something...
}
Is it OK to start the if statement by checking variable A and then continue with the else if by mentioning B? Doesn't this action change the context that was initially set when writing the first contition?
I would expect to see code like this:
if (condition1 about A) {
// do something...
} else if (condition2 about A) {
// do something...
} else ...
- or something similar about
B, - or something similar about both
AandBwith the use of&&,||.
My example comes from one of the Codeschool js courses and I found it a bit confusing. Is it OK to write if statements like this?
Aucun commentaire:
Enregistrer un commentaire