Shop OBEX P1 Docs P2 Docs Learn Events
How to escape multi levels of IF statements? — Parallax Forums

How to escape multi levels of IF statements?

T ChapT Chap Posts: 4,223
edited 2009-01-27 20:57 in Propeller 1
 Repeat     
   if routineA
   if routineB
   if ReadKeyPadA > 0
        spk.beep(19, 3000, 50)
        if PasswordCheck == true
          if doorpos == closed             '<<<<<<<<<<<
            MaxSpeed := MaxSpeedOpen
            newpos := oPos
            doorpos := open
            spk.beep(19, 2500, 50)
            repeat while ReadKeyPadA > 0    'stay here until button released
            waitcnt(20_000_000 + cnt)
          if doorpos == open               '<<<<<<<<<<<
            MaxSpeed := MaxSpeedClose
            newpos := cPos
            doorpos := closed
            spk.beep(19, 2500, 200)
            repeat while ReadKeyPadA > 0     'stay here until button released
            waitcnt(20_000_000 + cnt)




In the code above, if doorpos = closed, then when it gets to the next 'if doorpos = open', then the whole block cancels itself out, as the next if section resets the parameters back where they were. The solution I can use is to read the device twice like below:

 Repeat
   if ReadKeyPadA > 0
        spk.beep(19, 3000, 50)
        if PasswordCheck == true
          if doorpos == closed             '<<<<<<<<<<<
            MaxSpeed := MaxSpeedOpen
            newpos := oPos
            doorpos := open
            spk.beep(19, 2500, 50)
            repeat while ReadKeyPadA > 0   'stay here until button released
            waitcnt(20_000_000 + cnt)

   if ReadKeyPadA > 0
        spk.beep(19, 3000, 50)
        if PasswordCheck == true
          if doorpos == open               '<<<<<<<<<<<
            MaxSpeed := MaxSpeedClose
            newpos := cPos
            doorpos := closed
            spk.beep(19, 2500, 200)
            repeat while ReadKeyPadA > 0    'stay here until button released
            waitcnt(20_000_000 + cnt)



But this wastes time and has other implications, but it does work to a degree.

Can anyone suggest a method to back out of the entire if ReadKeyPadA > 0 section if the first section is TRUE, avoiding it canceling itself in the subsequent section?

Thanks

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-27 19:11
    elseif doorpos == open

    -Phil
  • T ChapT Chap Posts: 4,223
    edited 2009-01-27 19:37
    Thanks Phil, but I am not seeing how that solves it.

    In the first if doorpos == closed, if it IS closed then the line below it makes it become doorpos := open, then when it gets to the next if doorpos == open, it puts the variable back where it was, canceling the whole thing out.

    Maybe I am missing your point?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-27 20:21
    Sorry: I should've been more verbose I guess. What I meant was to replace the if doorpos == open with elseif doorpos == open. That way, if the top clause is executed, the elseif clause will be skipped.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 1/27/2009 9:22:33 PM GMT
  • T ChapT Chap Posts: 4,223
    edited 2009-01-27 20:37
    Phil

    I am sure there must be a more complex way to accomplish this? [noparse]:)[/noparse]

    Thanks!
  • mirrormirror Posts: 322
    edited 2009-01-27 20:57
    Read the Propeller Manual for the usage of "ABORT". It might be just what you're looking for!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.