Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT...CASE #92

Open
mdraith opened this issue Jul 3, 2024 · 1 comment
Open

SELECT...CASE #92

mdraith opened this issue Jul 3, 2024 · 1 comment

Comments

@mdraith
Copy link

mdraith commented Jul 3, 2024

Would be nice to have the following:

SELECT A
CASE 1:
  PRINT "A"
CASE 2 TO 4:
  PRINT "B-D"
DEFAULT:
  PRINT "OTHER"
ENDSELECT
@EricCarrGH
Copy link
Contributor

FYI, I had mentioned this in the past and @dmsc has replied:

No, I did not include a "SELECT CASE" statement, because is not that easy to implement: the result of the select expression needs to be stored in some place, and then compared with different values in each case. And from a speed perspective, a IF...ELIF...ELIF...ENDIF sequence using a variable should be faster.

.. in this thread: https://forums.atariage.com/topic/349675-fastbasic-help/

So, it likely would not be added.

Perhaps in the future, if enough people desire, a pre-processer could convert SELECT CASE to IF/ELIF/ENDIF statements before sending it to the compiler:

IF A=1
  PRINT "A"
ELIF A>=2 AND A<=4
  PRINT "B-D"
ELSE
  PRINT "OTHER"
ENDIF

comparing potential minified differences:

' SELECT CASE
S.A:C.1:?"A":C.2T.4:?"B-D":D.:?"OTHER":E.

' IF/ELIF
I.A=1:?"A":ELI.A>1A.A<5:?"B-D":EL.:?"OTHER":E.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants