Shop OBEX P1 Docs P2 Docs Learn Events
Syntax question — Parallax Forums

Syntax question

lardomlardom Posts: 1,659
edited 2011-11-22 10:43 in General Discussion
. I'm trying to write a statement that copies a value to the next 'empty' element in a variable array. I'm still working through the logic but I had a question about syntax
repeat until Y(index) == 0
   Y(index)++
Y(index) := X

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-22 09:25
    repeat while Y[index]
      index++
    Y[index] := X
    

    -Phil
  • lardomlardom Posts: 1,659
    edited 2011-11-22 09:36
    Thanks. :smile:
  • lardomlardom Posts: 1,659
    edited 2011-11-22 10:13
    I'm trying to state the rule. As 'Y[index]' increments I would think that the result value is copied to 'repeat'. I'm guessing that the rule is "Zero equals clear by default" which permits the loop to exit?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-11-22 10:22
    lardom wrote:
    I'm trying to state the rule. As 'Y[index]' increments ...
    I think you mean, "As index increments ..."
    lardom wrote:
    I'm guessing that the rule is "Zero equals clear by default" which permits the loop to exit?
    Yes. Y[index] in the while clause is true as long as the element being tested is non-zero. As soon as a zero element is found, the loop exits without executing again and incrementing the index.

    -Phil
  • lardomlardom Posts: 1,659
    edited 2011-11-22 10:43
    Thanks again Phil. :cool: That really is a big deal to me because a lot more programming language will make sense now.
Sign In or Register to comment.