lawl60ftw
|
  |
| Joined: 30 May 2009 |
| Total Posts: 3973 |
|
|
| 25 Oct 2012 12:00 PM |
I've always wondered this and never really payed attention when writing scripts like these, it always gets me and I usually don't notice the problem until I've written an entirely new script.
It's like my problem with not noticing " == true" and " = true" |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 12:01 PM |
| Depends on the language, in Lua we like to use elseif |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 12:05 PM |
They are two different things:
an elseif tuns an if statement inot a Case statement.
In case of this do that, case of this do the other case of last do finale.
|
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 12:08 PM |
It's a Case statement in Pascal.
In Basic, it's an On statement:
ON a=1, 5, -1, 0 GOTO 100, 200, 300, 400
bLAST FORM THE PAST, Brian
|
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 12:10 PM |
I forgot my line-number.
10 ON a=1, 5, -1, 0 GOTO 100, 200, 300, 400 |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 02:30 PM |
Right then, here's the difference:
"elseif" is like turning it into a switch statement (or is it case? Switch-Case?) so it's like this: If value = 1 then blah blah blah elseif 2 then blah blah elseif 3 then blah blah blah and so on.
"else if" is like putting an if statement inside an if statement, sort of. You would say something like: if script.Parent.IntValue = 1 then print("Value = 1") else if script.Parent.StringValue = ("blah") then print("IntValue does not equal 1 and StringValue equals blah")
So let's recap:
"else if" is like telling the script, if the value does not fit my specifications, then perform this other if statement.
"elseif" is like testing for multiple different values for different outcomes.
Direct answer to your question: It depends on what you're trying to do. |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 02:35 PM |
Just use elseif, as using else if would be redundant, and SockPuppetCow's script isn't even fully correct.
Lua Learners - Elite |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 03:19 PM |
| Meh. My script wasn't supposed to have any function, it was just an example. But I did get the point across did I not? |
|
|
| Report Abuse |
|
|
L2000
|
  |
| Joined: 03 Apr 2008 |
| Total Posts: 77448 |
|
|
| 25 Oct 2012 03:31 PM |
@Chaotic It wouldn't need to be fully correct; it still shows an example for the difference between the two, and gives a good explanation on it.
@OP It's one-word, so "elseif". However, if you wanted something to run for some but not for other cases, then you could use an else, inside that check the ifs, and then run the shared code. So, for example:
if condition then -- code elseif cond2 then -- code 2 -- shared code elseif cond3 then -- code 3 -- shared code end
That could be simpler with this:
if condition then -- code else if cond2 then -- code two elseif cond3 then -- code three end -- shared code end end
So, basically, for most if statements, you'd use elseif. |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2012 06:02 PM |
But my point is that you would never use else and then an if statement right after it. It's redundant, just use elseif.
Lua Learners - Elite |
|
|
| Report Abuse |
|
|