Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
In Terms of Best Practices with Else and ElseIf
#1
Found I have gone back to some old Qbasic routines to copy paste into present day code I've been working on and notice back then I never did use ElseIf but rather Else with IF in the following line, for example .

Code: (Select All)
a = 10
b = 12
c = 22
d = 60
If (a + b / 2) = c Then
    Print "Correct"
Else
    If (a + b * 2) = d Then
        Print "Correct"
    Else
        Print "Incorrect"
    End If
End If

Like the old adage goes, if its not broke don't fix it but, other than Elseif working better with the THEN and a block of code, would you classify code which uses Else with an IF on the following line as ok in terms of not worth the effort to change it?
Reply
#2
Not worth effort in the example given for sure! 

ElseIF really is effective when you have more and more mutually excluive cases, just like Select Case.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Good Coding with ElseIF Dimster 12 2,295 05-05-2023, 08:37 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)