Shop OBEX P1 Docs P2 Docs Learn Events
Help on Goto — Parallax Forums

Help on Goto

El PaisaEl Paisa Posts: 375
edited 2006-08-20 15:17 in Propeller 1
I really appreciate help to do this in spin,

·· Case K==$40
········ On Btn goto Btn1,Btn2,Btn3......Btnn

For each K, there is a Btn range from 0....N

Comments

  • SawmillerSawmiller Posts: 276
    edited 2006-08-20 15:11
    watch your indenting

    case k

    ·· $40 : case Btn

    ··············· Btn1 : K == $40 and Btn == Btn

    ················Btn2 :

    ··············· Btn3 :

    ·· other :· do other stuff if K <> $40


    somthing·like this nested case if your looking for 2 things ,irst k = $40 and then which button ?
    of course you could use a if statment for the outside case if your only looking for $40 before checking for btn states

    dan
  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-20 15:17
    You can't do this directly in SPIN ... There are no GOTOs. This does look like a great table driven problem (although you didn't say much about the "K"s). You don't give any information about the range of K values or the total number of "BtnN" choices. One thought would be a table with an entry for each K value that contains the K value, the value of N for each K, and a list of N values representing the BtnN choices. One entry for the example you gave, but with a N of 5 and BtnN values from say 5 to 9 (they don't have to be in order).
    Table byte     1                               ' number of entries
             byte     $40, 5, 5, 6, 7, 8, 9
    
    


    You'd have a whole bunch of such entries, search them with a little routine:
    PRI search(K,Btn) | i, p
      p := 1
      repeat i from 1 to Table[noparse][[/noparse]0]
        if K == Table[noparse][[/noparse]p]
          return Table[noparse][[/noparse]p+1+Btn]
        else
          p += Table[noparse][[/noparse]p+1] + 2
      return 0
    
    


    You could add range checking on the value of Btn in the line after the "if". You could substitute some other default action if K isn't in the table. You'd follow a call to this with a CASE statement for the actions
      CASE search(Kvalue,BtnValue)
        0: ' default
        5: ' K of $40, Btn1
        6: ' K of $40, Btn2
        ....
        9: ' K of $40, Btn5
    
    
Sign In or Register to comment.