I apologize if this sounds silly, as I'm completely new to programming.
My question is is that are you not allowed to use additional if clauses after an else? Is there a way around it?
I apologize if this sounds silly, as I'm completely new to programming.
My question is is that are you not allowed to use additional if clauses after an else? Is there a way around it?
You can use
But maybe I got the question wrong, you can start as many if clauses after an else as you wantCode:if (..) do this else if (..) do that else if (..) .... else
Last edited by Gauloises; 06-03-2011 at 07:00 AM.
Use an else if before the else
Code:if (first) { ... } else if (second) { ... } else if (third) { ... } else // All others { ... }
Thank you for the help! I did a math problem using an 'if' and an 'else' clause. After that I wanted to calculate a separate entity that is dependent on the original math problem, so I tried using an 'if' clause after the 'else' clause of the math problem, but it ignored my 'if' statement. So are you saying that if I use an 'else if' clause for the separate entity it will work?
Can you post the code that did not work like you wanted?
The one thing that we can guarantee is that it did not "ignore your if statement". If you put the if statement inside the else clause, then naturally it will only happen when the else clause happens. If the test of the if statement isn't true, then nothing will happen unless you provide an else to go with it. You should post your code to show what you mean.
Thank you everyone for your help. I realized I made a silly mistake of adding a semicolon after the if statement. After I deleted that everything worked out. Thank you!!