Menu

end of loop seen as variable

Jonny!!!
2008-06-09
2013-05-30
  • Jonny!!!

    Jonny!!! - 2008-06-09

    While working on a program with 2 nested-nested do-loops, GCBASIC came up with a syntax error. After looking at the generated assembly file, GCBASIC was interpreting a command line "LOOP UNTIL LoopBlink = 3" as a variable name, instead of a command line. This "variable" GCBASIC called "LOOPUNTILLOOPBLINK" (this is the 2nd nested loop in a nested loop... look at the code!)

    I was able to solve this little debacle by placing the nested loop (which is inside another, 'main' loop) last command from "LOOP until innerblink = 10" to only "LOOP", and then moving the "until innerblink = 10" portion to the beginning of the loop, so it read "do until innerblink = 10"

    This is the running code:

        if ModeValue = 4 then 'this is altering speed blink
            do
                blinkloop = 0
                innerblink = 0
                do
                    for BlinkSpeed = 18 to 9
                        set frontright on
                        set frontleft off
                        set backright off
                        set backleft on
                        wait blinkspeed 10ms
                        set frontright off
                        set frontleft on
                        set backright on
                        set backleft off
                        wait blinkspeed 10ms
                        if MODEBTN = on then ModeSet
                    next
                    for BlinkSpeed = 9 to 18
                        set frontright on
                        set frontleft off
                        set backright off
                        set backleft on
                        wait blinkspeed 10ms
                        set frontright off
                        set frontleft on
                        set backright on
                        set backleft off
                        wait blinkspeed 10ms
                        if MODEBTN = on then ModeSet
                    next
                    blinkloop = blinkloop + 1
                loop until blinkloop = 2

                'repeats this cycle 2 amount of times, then pattern changes:
                '(this repeats 10 times, starts over from beginning)
                do until innerblink = 10
                    LoopBlink = 0
                    do
                        SET FRONTLEFT ON
                        SET FRONTRIGHT OFF
                        SET BACKLEFT OFF
                        SET BACKRIGHT ON
                        wait 65 ms
                       
                        if MODEBTN = ON then ModeSet
                        SET FRONTLEFT OFF
                        SET BACKRIGHT OFF
                        wait 65 ms
                        LoopBlink = LoopBlink + 1
                       
                        if MODEBTN = ON then ModeSet
                    loop until LoopBlink = 3
                   
                    LoopBlink = 0
                    do
                        SET FRONTLEFT OFF
                        SET FRONTRIGHT ON
                        SET BACKLEFT ON
                        SET BACKRIGHT OFF
                        wait 65 ms
                       
                        if MODEBTN = ON then ModeSet
                        SET FRONTRIGHT OFF
                        SET BACKLEFT OFF
                        wait 65 ms
                        LoopBlink = LoopBlink + 1
                       
                        if MODEBTN = ON then ModeSet
                    loop until LoopBlink = 3
                    innerblink = innerblink + 1
                loop
                'if MODEBTN = on then ModeSet
            loop
        end if

     
    • Hugh Considine

      Hugh Considine - 2008-06-30

      The code you posted works fine for me, even when I moved the until loopblink = 10 to the end of the loop. Could you please post the exact section of code that does not work?

      When trying to compile that code, I added this to the start:

      #chip 16F88, 20
      #define frontright PORTB.0
      #define frontleft PORTB.1
      #define backright PORTB.2
      #define backleft PORTB.3
      #define MODEBTN PORTA.0

      Is that similar to what you have?

       
    • Nobody/Anonymous

      Yes, very similar:

      #CHIP 12F683, 4
      #CONFIG OSC = INT, MCLR = OFF

      #DEFINE FRONTLEFT GPIO.5
      #DEFINE FRONTRIGHT GPIO.4
      #DEFINE BACKLEFT GPIO.0
      #DEFINE BACKRIGHT GPIO.1
      #DEFINE MODEBTN GPIO.3
      #DEFINE MODEINDICATE GPIO.2

      It appears that this problem is corrected in the new version of GCBASIC (I seem to have a hard time keeping it up-to-date ;) )

      However, a new problem is presented in the new version, that is not present in the previous version of GCBASIC. I explained it in post http://sourceforge.net/forum/forum.php?thread_id=2073279&forum_id=596084

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.