Shop OBEX P1 Docs P2 Docs Learn Events
Help with repeat command — Parallax Forums

Help with repeat command

mynet43mynet43 Posts: 644
edited 2007-04-24 18:36 in Propeller 1
I've been tracking a little bug for a while and I finally found the problem.

The code I'm running is:

cols := 128 (really a constant in the CON block)
yloc := 0 (xloc, yloc and loc are all longs in the VAR block)

repeat xloc from cols - 1 to 0 step -1
loc := xloc + yloc*cols
if screen[noparse][[/noparse]loc] <> $20 ' continue until first non-space char
quit

This is part of a routine to process the end key on the keyboard.

In debugging this, I found that the "step -1" doesn't work (even when I make it a variable, I also tried -2).
The value of xloc stays at 127...

When I remove the "step -1", the loop works perfectly.

The syntax looks like the example on page 296 of the manual.

Can someone see what I'm doing wrong?

Thanks for your help.

Jim

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-24 18:16
    It's a "feature". The repeat works a bit differently than you expect. The interpreter looks at the initial and final values and chooses a step direction based on whether the initial value is less than the final value (positive step) or the initial value is greater than the final value (negative step). The step size is supposed to normally be positive. In your case, the interpreter is subtracting -1 (or adding +1) to xloc. Just change the step to 1 and it should work fine.
  • mynet43mynet43 Posts: 644
    edited 2007-04-24 18:36
    Thanks Mike for the quick reply. It seems counter intuitive compared to other languages, but I understand.

    It seems like step -1 should mean what it says[noparse]:)[/noparse]

    For now, I'll just leave off the "step".

    Thanks again.

    Jim
Sign In or Register to comment.