I don’t believe that you “can’t” or even “shouldn’t” replace an *else
statement with an *if
statement, but that it changes the burden of labor. Depending on your personality, and what you’re trying to accomplish, that may (or may not) be beneficial.
As has been mentioned before, *else
automatically “sweeps up” everything preceding *if
statements may have left behind, while excluding everything else. Thus, replacing it with another *if
requires extra vigilance on your part to ensure nothing is accidentally skipped or accidentally triggering multiple statements. (Obviously, skipping something or triggering multiple statements on purpose isn’t a problem.)
Yes, *else
requires a *goto
below it, and a matching *label
elsewhere, increasing the length of your code. However, duplicating the effect of *else
with only *if
will make each *if
statement longer, somewhat reducing the benefit of skipping *goto
. And in situations where you’re planning on using *goto
anyway, you’ll be making your code longer.
Looking back at the “dapper” example @Fiogan gave, you could easily replace:
*elseif (dapper > 30)
*goto you_do_fairly_well
*else
*goto everything_is_a_disaster
With something like this:
*if (dapper <= 50) and (dapper > 30)
*goto you_do_fairly_well
*if (dapper <= 30)
*goto everything_is_a_disaster
Or, assuming your numeric variables will only ever contain integers and never decimals, something like:
*if (dapper < 51) and (dapper > 30)
*goto you_do_fairly_well
*if (dapper < 31)
*goto everything_is_a_disaster
You can see how pure *if
will save some coding if you don’t need *goto
(or only need it on a few of your *if
statements but not all,) but becomes less helpful the more you need *goto
.
Also, think about what would happen if you accidentally coded *if (dapper < 30)
instead of either *if (dapper <= 30)
or *if (dapper < 31)
. An easy enough typo to make, right? But then what happens if an MC has exactly 30 {dapper}
? They won’t get the result for “greater than 30,” because 30 isn’t greater than itself. But they won’t get the result for “less than 30” either. It will simply “fall out” of the *if
statements without doing anything.
If you take the extra effort to account for situations like that, it should be perfectly fine to use nothing but *if
. But that’s exactly what I mean by changing the burden of labor — you’ll save effort on coding *goto
and *label
, but you’ll spend effort making sure all possible situations are functioning as you intend.
So, should you use *else
instead of *if
? That’s going to depend partly on which type of effort annoys you more, and partly on whether you’re already using *goto
, isn’t it?
I genuinely believe the answer to Should I? is “It’s situational.” I don’t believe either method will always be easier or more reliable. A writer who loves puzzling out how something will work, but dislikes unnecessary typing will likely find great benefit in a chain of pure *if
. Clearly, @Shawn_Patrick_Reed is this type of writer, and your comments make me suspect you are as well. However, a writer who doesn’t mind typing but dislikes trying to figure out what the code is actually doing and how that compares to what it needs to be doing will likely find great benefit in *else
.
What’s better for you might be worse for someone else, and vice versa.