PDA

View Full Version : elseif


dhtmlx
01-04-2003, 03:03 AM
is there such a thing as elseif. For example if I wanted to do

if(something) {
do something
} elseif(something else) {
so soemthing else
}

is that possible?

chrismiceli
01-04-2003, 03:10 AM
if(something) {
do something
} else if(something else) { // there is a space!
so soemthing else
}

dhtmlx
01-04-2003, 03:14 AM
stupid stupid me!!Probably as you were typing that I found it out.


Thanks Anyway =/ sorry for wasting ur time

RadarBob
01-04-2003, 05:22 PM
Originally posted by chrismiceli
if(something) {
do something
}elseif(something else) { // there is a space!
so soemthing else
}

Are the brackets right? Or do it go like this:

if (somthing){
}else{
if (something else) {
}else{
If (default) {
}

Personally, I prefer the switch statement over else/if. I think it is less error prone and clearer to the reader and easier to modify.

chrismiceli
01-04-2003, 08:29 PM
i like the switch to, but the brackets would work.

if(something) {
do something // is executed if something is true.
} else if(something else) { // the first line is executed, which has stuff in brackets, so they would exectute also if somethine else was tru
so soemthing else
}