Shop OBEX P1 Docs P2 Docs Learn Events
Repeat loop using pin input — Parallax Forums

Repeat loop using pin input

AJMAJM Posts: 171
edited 2009-08-13 19:41 in Propeller 1
This is a very simple question but maybe beneficial to others:

Can I base a repeat loop off of an input? What if the input changes?


Basically, this:


X := whatever.firstobject           '' the first object sets variable 'X' to the pin that is high

repeat until/while ina[noparse][[/noparse]X] == 0/1
   rest of code
   ....
   ....





Anyway, let me know if this is correct or if I need to think about this differently

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-13 19:18
    Yes. The expression after the UNTIL or WHILE can be anything. If it's non-zero, it's considered to be true. If it's zero, it's considered to be false.

    You can even put an assignment statement there since an assignment has a value (the value after assignment of the left side).
  • AJMAJM Posts: 171
    edited 2009-08-13 19:41
    Thanks Mike!
Sign In or Register to comment.