do / until / while / loop

techElder

Well-known member
Can't get to hardware to test this, but the double do/loop test passes syntax in PE6. Guess I never ran across this kind of double test before.

Code:
' sample do nothing code
retry = 12
countTo = 10
wrong = 0
do while ii <= retry                    ; test here for execution within loop
   for countFrom 0 to countTo
      if wrong = 1 then
         inc ii
      endif
   next countFrom
loop until countFrom > countTo   ; test here for complete execution of for/next
 

hippy

Technical Support
Staff member
Can't get to hardware to test this, but the double do/loop test passes syntax in PE6. Guess I never ran across this kind of double test before.
Not sure what the actual question is but a conditional on both DO and LOOP is valid syntax and will work. Underlying all multi-line block commands are single-line IF-THEN commands so -

Code:
do while ii <= retry
  [i]code[/i]
loop until countFrom > countTo
Is the equivalent of -

Code:
DoLoopStart:
  If ii > retry Then DoLoopDone  
  [i]code[/i]
  If countFrom <= countTo Then DoLoopStart
DoLoopDone:
Note the compiler adjusts the comparison used in DO-WHILE and LOOP-UNTIL to create an optimised IF-THEN statement.
 

rq3

Senior Member
Can't get to hardware to test this, but the double do/loop test passes syntax in PE6. Guess I never ran across this kind of double test before.

Code:
' sample do nothing code
retry = 12
countTo = 10
wrong = 0
do while ii <= retry                    ; test here for execution within loop
   for countFrom 0 to countTo
      if wrong = 1 then
         inc ii
      endif
   next countFrom
loop until countFrom > countTo   ; test here for complete execution of for/next

I'm certainly not the guy to be reviewing code, but how does "wrong" get to be "1" so that countFrom will increment?
 

inglewoodpete

Senior Member
I'm certainly not the guy to be reviewing code, but how does "wrong" get to be "1" so that countFrom will increment?
Since this is a code snippet, we don't know what is defined in the rest of the program. "wrong" could easily be updated in the (potential) interrupt routine.
 

techElder

Well-known member
You guys are too literal to be funny! :D :D :D

PS. Hippy guessed right! As usual!

PPS. Fantastic software from RevEd!
 
Last edited:

erco

Senior Member
Can't get to hardware to test this, but the double do/loop test passes syntax in PE6.
Aw, come on, Tex. Don't you keep a Picaxe in your wallet for emergencies, like the rest of us? There's no telltale ring, but sometimes the pins poke through. :)
 

techElder

Well-known member
Aw, come on, Tex. Don't you keep a Picaxe in your wallet for emergencies, like the rest of us? There's no telltale ring, but sometimes the pins poke through. :)
I ain't tellin' what that weared out ring is from. ;D

Thanks, folks. I was just glad to solve a do/loop for/next if/then problem and reduce the code in a subroutine. Guess I didn't really explain the situation well enough.

I'm hoping that the next 45 posts will use the above snippet of code to create a line-following robot or at least a laser intervalometer for me! :D :D :D
 
Top