Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Switch-case statements

    Comments & Feedback
    2
    4
    32
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      Fuze4Fun last edited by

      I am a Windows developer although not active in this now, just occasional personal projects these days, so have a fair amount of programming knowledge but not in developing games However, getting the Fuze4 programming language for the Switch was just too good to miss especially at the bargain price of £4.99. I've only just started looking at what can be achieved and its impressive. I marvel at the many excellent games/demos that people have developed.

      I've been looking at the Fuze4 language in a little detail and it looks to provide some good commands for structured programming with functions and structures. I was a little surprised it does not offer switch statements such as this in the C programming language:

      switch( myvar ) {
         case 1:
            print("Hello")
         case 2:
            print("Goodbye")
        default
           print("What's up dock?"
      }
      

      This avoids all those nested if-then statement blocks and I think makes the code more readable.

      if myvar = 1 then 
         print("Hello")
      else if myvar = 2 then
         print("Goodbye")
      else
         print("What's up dock?")
      endif
      

      This is a simplistic example, but with more nested if-then-else conditions it would be apparent the switch statements make the code easier to read and manage. Many other languages support these switch statements in one form or another. However, this has not hampered the language and what can be achieved with it, so this is just an observation and at the end of the day, it's more important what people do with what is available. :-)

      vinicity 1 Reply Last reply Reply Quote 0
      • vinicity
        vinicity F @Fuze4Fun last edited by

        @fuze4fun
        It's a bit annoying, but one gets used to it eventually!

        I searched through the forum, and back in 2019, the devs wrote that switch statements would be added eventually. Who knows?

        PS, your second example is missing an endif. To keep things from getting messy, I usually put the extra endifs on the same row, like so:

        if statement then
           //code
        else if statement_2 then
           //code
        else
           //code
        endif endif
        
        1 Reply Last reply Reply Quote 0
        • F
          Fuze4Fun last edited by

          Yes, my example was not good because it should also have been if myvar == 1. Switching between languages can get confusing!

          1 Reply Last reply Reply Quote 0
          • F
            Fuze4Fun last edited by

            Hi, just realised something about my second example. I think the confusion is the 'else if' statement, which I should have written as elseif without the space. This makes all the difference! I'm currently developing a Windows app using an older basic-language called PowerBasic, and there is an elseif statement (without the space) and with this the code example I gave does not require the extra endif, but with the space then you are correct, the extra endif is needed. So just a good example of how careful we must be switching between different programming tools.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post