Shop OBEX P1 Docs P2 Docs Learn Events
Multiple "For Next Loop" problem... — Parallax Forums

Multiple "For Next Loop" problem...

WaltsWorkerWaltsWorker Posts: 1
edited 2013-02-13 19:15 in BASIC Stamp
Hello,
I'm running a BS2SX using the 2.2.5 software. I'm having a problem with the code executing the 'outer loop' - as it only goes though the 'inner loop.'
==================
Pump1:'Current pump time is 33 seconds
OUT2 = 0 ' Set Tally to Off
OUT15 = 1 ' turn on the pump!
FOR Pa = 1 TO 0 ' outter loop
FOR POn = 49999 TO 0 ' inner loop
NEXT
NEXT
OUT15 = 0 ' turn the pump off
===================
If I change "Pa = 1 TO 0" to any other number the time stays the same.
Thanks for any help!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-02-13 12:36
    You didn't indicate what kinds of variables you're using: words, bytes, nibbles, or bits. This loop will only work if POn is a word. The following example works fine. It takes about 2 minutes to run:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
      a  VAR  Word
      b  VAR  Word
      DEBUG "test program",CR
      FOR a = 1 TO 0
      DEBUG "a=",DEC a,CR
      FOR b = 49999 TO 0
      IF b > 49990 OR b < 10 OR (b//1000) = 0 THEN DEBUG "b=",DEC b,CR
      NEXT
      NEXT
      DEBUG "all done",cr
      stop
      END
    
  • bluejaybluejay Posts: 131
    edited 2013-02-13 19:15
    Mike Green wrote: »
    You didn't indicate what kinds of variables you're using: words, bytes, nibbles, or bits. This loop will only work if POn is a word. The following example works fine. It takes about 2 minutes to run:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
      a  VAR  Word
      b  VAR  Word
      DEBUG "test program",CR
      FOR a = 1 TO 0
      DEBUG "a=",DEC a,CR
      FOR b = 49999 TO 0
      IF b > 49990 OR b < 10 OR (b//1000) = 0 THEN DEBUG "b=",DEC b,CR
      NEXT
      NEXT
      DEBUG "all done",cr
      stop
      END
    



    The code won't run as is. This will work.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a VAR Word
    b VAR Word
    DEBUG "test program",CR
    FOR a = 1 TO 0
    DEBUG "a=",DEC a,CR
    FOR b = 49999 TO 0
    IF b > 49990 OR b < 10 OR (b//1000) = 0 THEN DEBUG "b=",DEC b,CR
    DEBUG "b=",DEC b,CR
    ENDIF
    NEXT
    NEXT
    DEBUG "all done",cr
    stop
    END[/code][/QUOTE]
Sign In or Register to comment.