Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Good Coding with ElseIF
#4
Sometimes I wish BASIC were just like Lua or Pascal, insisting only on boolean result out of "IF... THEN".

Because it's not, because it's zero for "false" and any other value for "true", I have to design things with the first form. Like I said, I'm trying to think of a good way which has a complex "boolean" expression. Yet I'm not that confident neither in doing it in Lua, and that interpreter has given me problems with some of my ineffective designs.

Another thing is that QB64(PE) doesn't (yet) feature short-circuit evaluation, while Lua does. If it did, then even more things could be done with only one "IF" in the huge "IF... THEN... ELSEIF... ELSE... END IF" block. I wouldn't like short-circuit evaluation supported with "ANDALSO" and "ORELSE" keywords though, better with a compiler switch, if the aim isn't to be compatible with Freebasic and Visual Basic code.

Another thing is to gather the "IF" and "ELSEIF" stacks carefully when testing the same variable. Consider:

Code: (Select All)
IF i > 5 THEN
:
ELSEIF i > 10 THEN
:
END IF

What if you want code posted under "i > 10" to be executed while "i" is eleven at least? Instead of code that is executed in the first section? Something like this is a common mistake made with "IF... THEN... ELSEIF... ELSE... END IF". This was just an example with one variable involved, which could be rewritten with "SELECT CASE... END SELECT". But there is code which need to test two or more variables at the same time and relying on function results and other stuff.

Block "IF" is one of the best things that ever happened to BASIC. Together with looping structures and real subprograms, it made "GOTO" and line numbers unnecessary.

LOL Steve will answer you with more detail soon.
Reply


Messages In This Thread
Good Coding with ElseIF - by Dimster - 05-04-2023, 04:11 PM
RE: Good Coding with ElseIF - by mnrvovrfc - 05-04-2023, 04:45 PM
RE: Good Coding with ElseIF - by Dimster - 05-04-2023, 07:22 PM
RE: Good Coding with ElseIF - by mnrvovrfc - 05-04-2023, 09:12 PM
RE: Good Coding with ElseIF - by James D Jarvis - 05-04-2023, 09:23 PM
RE: Good Coding with ElseIF - by TerryRitchie - 05-04-2023, 09:51 PM
RE: Good Coding with ElseIF - by James D Jarvis - 05-05-2023, 01:39 AM
RE: Good Coding with ElseIF - by mnrvovrfc - 05-04-2023, 10:09 PM
RE: Good Coding with ElseIF - by James D Jarvis - 05-05-2023, 01:35 AM
RE: Good Coding with ElseIF - by Dimster - 05-05-2023, 01:03 PM
RE: Good Coding with ElseIF - by bplus - 05-05-2023, 05:38 PM
RE: Good Coding with ElseIF - by Dimster - 05-05-2023, 08:11 PM
RE: Good Coding with ElseIF - by bplus - 05-05-2023, 08:37 PM



Users browsing this thread: 1 Guest(s)