jeudi 9 juillet 2015

How should I structure those nested if statements?

I have a nested if like this:

  if (condition 1)
    if (condition 2)
        statement
    end
else
    if (condition 3)
       statement
    end
end

The two statements are the same. Written like this, it goes to condition 3 only when condition 1 is not satisfied, while if condition 2 is not satisfied it interrupts the execution of the statements. Instead, I want my code to skip to condition 3 also in the case only condition 2 is not satisfied (and condition 1 it is). Should I use any "break" or "switch" or do I need just to change the disposition of my nested if?

Edit: Basically I want that if condition 1 is satisfied but condition 2 is not it skips to condition 3. In other words, I would like that condition 3 is verified if: 1) condition 1 is not satisfied; 2) condition 1 is satisfied but condition 2 is not satisfied.

Aucun commentaire:

Enregistrer un commentaire