jaytea commented on a Page, Sgkk alias  -  Dec 21, 2011

all should be elseif after the first ifff.

I often run into unworkability when I use an elseif right after an if upon sockread.

forgive me, but i sense there's still some confusion about what is one of the most fundamental programming concepts.

if (A) {

}
if (B) {

}
if (C) {

}

here, each of the conditions 'A', 'B' and 'C' are tested (unless the code is forced to end prematurely with /halt or /return). the if statements act independently. even in the case where 'B' can only be true if 'A' is false, or 'C' can only be true if both 'A' and 'B' are false, they are all still tested.

if (A) {

}
elseif (B) {

}
elseif (C) {

}

here, 'B' is only tested if 'A' is false. and 'C' is only tested if both 'A' and 'B' are false. when you're dealing with the case mentioned earlier, this code is ideal especially if 'B' and 'C' are computationally expensive checks, or if you want a final 'else' default case, or simply to adhere to good practice as in this snippet's case.

if you're not comfortable with a certain language construct then TEST IT. don't test it in the middle of your socket script, or with some other 1000 line script; test it in a simplified bit of code, and in a variety of different ways until you understand how it works.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.