Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ELSIF
#1
For instance, suppose a game with 5 levels of difficulty, that needs to perform certain tasks depending on this. In ZX BASIC it will look like this:

Code:
IF level = 1 THEN
    ...
ELSE
    IF level = 2 THEN
        ...
    ELSE
        IF level = 3 THEN
            ...
        ELSE
            IF level = 4 THEN
                ...
            ELSE
                ...
            END IF
        END IF
    END IF
END IF

My suggestion is to add a new keyword "ELSIF", so the code above could be simplified as follows:

Code:
IF level = 1 THEN
    ...
ELSIF level = 2 THEN
    ...
ELSIF level = 3 THEN
    ...
ELSIF level = 4 THEN
    ...
ELSE
    ...
END IF

I know this is not an important feature (the kind of stuff they call "syntactic sugar"), but since this is probably very easy to implement in the compiler and should be very convenient for several programs, I'm suggesting it anyway Smile
Reply
#2
This already exists, following FreeBasic convention. It's called ELSEIF.
I choose this name instead of ELSIF or ELIF because we decided to follow FreeBasic dialect Wink
Reply
#3
So that's the reason I could not find it!

Thanks Smile
Reply
#4
The list of reserved words is your friend.

<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Identifier#Reserved_Identifiers">http://www.boriel.com/wiki/en/index.php ... dentifiers</a><!-- m -->
Reply
#5
I never heard about ELSIF before.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#6
Confusedhock:
Well, it's ELSEIF not ELSIF. It was implemented long ago.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)