Announcement

Collapse

Documentation

All current versions of the PowerBASIC documentation are available for download/viewing here:

PowerBASIC Links
See more
See less

Select Case Always

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Select Case Always

    I ran into something I didn't know (not an unusual occurrence by a long shot, but anyway...) I found that you can put code between the SELECT and the first CASE and it is always executed. I couldn't find anything in the docs about it. I just thought it was interesting. Ver 10.04.

    Code:
      LOCAL X AS LONG
      X = 2
    
      SELECT CASE X
      ? "Always"
      CASE = 1: ? "1"
      CASE = 2: ? "2"
      CASE = 3: ? "3"
      END SELECT

  • #2
    This came up years ago and Bob Zale's reaction to it was "Don't do it!"
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

    Comment


    • #3
      Originally posted by Rodney Hicks View Post
      ..."Don't do it!"
      For me it was a good thing. I used that line for debug information. It displayed what the select was before the cases were executed.

      Down side...Any statements that change X in my example were misleading because the SELECT already made it's decision which CASE to execute.

      Comment


      • #4
        I don't recall any bad effects doing that, just the word from above.
        Rod
        In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

        Comment


        • #5
          This could be very confusing changing the value of the SELECT test before the CASE executes
          Code:
            LOCAL X AS LONG
            X = 2
          
            SELECT CASE X
          
            X = 3
          
            CASE = 1: ? "1"
            CASE = 2: ? "2"
            CASE = 3: ? "3"
            END SELECT
          2 still executes after X was changed to 3.

          Comment


          • #6
            But the value of x is 3 after the END SELECT, so yes, one could confuse one's self.
            To further confuse one's self put : x+=x after "2".
            Rod
            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

            Comment

            Working...
            X