PDA

View Full Version : Usage of DO/LOOP, DO WHILE/LOOP, DO / LOOP UNTIL



Petr Schreiber
29-05-2007, 07:55
Hi,

another loop related stuff


uses "Console"

dim CountSheep as byte

Console_Writeline("Pure DO/LOOP")

' -- Classic infinite loop
' -- NOTE: To leave loop you must use EXIT statement
CountSheep = 0
do

incr CountSheep

Console_Writeline("-- Sheep :"+STR$(CountSheep))

if CountSheep = 10 then exit do

loop

Console_Writeline("Press ENTER...")
console_Readline

Console_Writeline("Test DO WHILE/LOOP")

' -- Loop with condition which must be TRUE to PERFORM cycle
' -- NOTE: If the condition does not equal to TRUE on start, NO cycle is performed
' - try to change "CountSheep = 0" to "CountSheep = 10"
CountSheep = 10
do WHILE CountSheep < 10 ' -- Valid for CountSheep = 0 ... 9

incr CountSheep

Console_Writeline("-- Sheep :"+STR$(CountSheep))

loop

Console_Writeline("Press ENTER...")
console_Readline

Console_Writeline("Test DO/LOOP UNTIL")

' -- Loop with condition on end which must be TRUE to LEAVE cycle
' -- CAUTION ! This way at least one loop is performed always
CountSheep = 0
do

incr CountSheep

Console_Writeline("-- Sheep :"+STR$(CountSheep))

loop until CountSheep = 10 ' -- If this is true we leave loop

Console_Writeline("End of demonstration, press ENTER to quit...")
console_Readline


Bye,
Petr

ErosOlmi
29-05-2007, 15:30
Substituted


' - try to change "CountSheep = 0" to "CountSheep = 10"
CountSheep = 10

with


' - try to change "CountSheep = 0" to "CountSheep = 10"
CountSheep = 0


Thanks
Eros

Petr Schreiber
29-05-2007, 16:06
Thanks Eros,

I had probably testing version in clipboard :-[


Bye,
Petr