Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 loop within a loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
n00b.skillz




PostPosted: Sat Jan 13, 2007 5:52 pm   Post subject: loop within a loop

okay well i need to make a loop within a loop but i need to be able for the loops to be different...somehow... as i am ending both loops with exit when and the one loop starts the line before the other... any suggestions? is there anyway i can make the loops distinct as in loop1 and loop2 and then exit loop1 when... exit loop2 when... that sorta of thing..... is this possible?
Sponsor
Sponsor
Sponsor
sponsor
neufelni




PostPosted: Sat Jan 13, 2007 6:36 pm   Post subject: RE:loop within a loop

Yes this is possible. Here is an example program. It counts to 5 three times.
Turing:
var i : int := 0
var n : int := 0

loop
    loop
        i += 1
        put "Inner loop count: ", i
        exit when i = 5
    end loop
    n += 1
    i := 0
    put "Outer loop count: ", n
    exit when n = 3
end loop

So basically you just have an outer loop and an inner loop. The first exit when is for the inner loop and the second one is for the outer loop.
n00b.skillz




PostPosted: Sat Jan 13, 2007 7:25 pm   Post subject: Re: loop within a loop

yea thanks alot i tried this before but it wasn't working and now i tried it again and it works... i must've keyed in something wrong by accident before... thanks for clearing this up! Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: