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

  • Rodney Hicks
    replied
    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".

    Leave a comment:


  • Frank Rogers
    replied
    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.

    Leave a comment:


  • Rodney Hicks
    replied
    I don't recall any bad effects doing that, just the word from above.

    Leave a comment:


  • Frank Rogers
    replied
    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.

    Leave a comment:


  • Rodney Hicks
    replied
    This came up years ago and Bob Zale's reaction to it was "Don't do it!"

    Leave a comment:


  • Frank Rogers
    started a topic Select Case Always

    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
Working...
X