PDA

View Full Version : REPEAT loops



codeking
02-02-2007, 12:01 AM
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

Newzed
02-02-2007, 12:20 AM
Yes.· For example:

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

Sid

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

Newzed@aol.com (mailto:Module?Newzed@aol.com)
·

Mike Green
02-02-2007, 12:29 AM
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 "="

asterick
02-02-2007, 12:35 AM
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