Computer Science Canada

Repeat the loop

Author:  ashan [ Thu Feb 19, 2004 7:07 pm ]
Post subject:  Repeat the loop

Hi,

I'm a beginner in programming. Do any of you know how to repeat a loop (afterr you exit it) without cutting and pasting the whole loop command again?, is that the only way to do it?
pls help me!!

Thanks & regds

Ashan

Author:  Mazer [ Thu Feb 19, 2004 7:15 pm ]
Post subject: 

It depends on how you want to do it. In some cases, you could just have the loop inside another loop. But that'd be weird for me to explain, and if you wanted to use the loop somewhere else instead of immediately after it finishes, that'd be useless.
What I'm thinking would be best is to have a proc with the loop that you call whenever necessary.
code:

proc loopstuff
    loop
        % stuff happens here!
        exit % make sure you exit sometime
    end loop
end loopstuff

loopstuff
put "That was... 'fun'"
loopstuff
put "OK, that's enough."
[/code]

Author:  RottenPunk [ Thu Feb 19, 2004 7:18 pm ]
Post subject: 

im pretty new with turing too and i wasn't sure of a command to restart a loop in an if statement either but in one of my programs i fund that i put something like the following:

code:
get retry
if retry="n" or retry="N" then
exit
end if

this tells the program that if the input is n or N than the program terminates but if anything else is typed the loop starts over. at leaset that is how mine works. hope that helps

Author:  ashan [ Thu Feb 19, 2004 7:42 pm ]
Post subject:  thanks, that works

hey,

thanks man!

that works!

u guys are great!!

thanks again

ashan


: