Shop OBEX P1 Docs P2 Docs Learn Events
REPEAT loops — Parallax Forums

REPEAT loops

codekingcodeking Posts: 39
edited 2007-02-01 16:35 in Propeller 1
repeat count decreases count once every loop and stops when is gets to zero.· But can I make a loop that loops until I say count = 0?· For example:

REPEAT UNTIL count = 0
·· IF something
······ count = 0

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-02-01 16:20
    Yes.· For example:

    PUB writestr | p···
    ··· p := 0
    ··· print_string(string(13,13,"· Enter starting address to read:· "))
    ··· repeat until· (msg[noparse][[/noparse]p] :=key.getkey) == 13
    ····· print(msg[noparse][[/noparse]p++])
    ··· print(13)
    ··· sendstr(@msg)
    ··· print(cls)

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Don't have VGA?

    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-01 16:29
    codeking,
    Here are a couple of examples:
    repeat count      'this sets a maximum # times
       if something
          quit             'exit the loop if something is true
    
    repeat until count == 0   'use "==" here instead of "="
       if something
          count := 0    ' use ":=" here instead of "="
    
    
  • asterickasterick Posts: 158
    edited 2007-02-01 16:35
    codeking said...
    repeat count decreases count once every loop and stops when is gets to zero. But can I make a loop that loops until I say count = 0? For example:


    REPEAT UNTIL count = 0

    IF something

    count = 0

    Also a cute trick to remember is:

    repeat while count
        if something
            quit
    
    



    Since Non-zero is considered true. Saves you a logical comparison. (This was done in one of the examples)

    Great for things like

    repeat while LOCKSET(myLock) ' Halt for semaphor
Sign In or Register to comment.