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

Username:   Password: 
 RegisterRegister   
 y doesnt this have an output??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
person




PostPosted: Sat Mar 12, 2005 7:40 pm   Post subject: y doesnt this have an output??

code:

for x : 0 .. 20
    for decreasing y : 1 .. 20
        locate (x, y)
        put x
    end for
end for


y doesnt this output anything?[/quote]
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Mar 12, 2005 7:48 pm   Post subject: (No subject)

It skips the second for loop because 1 is less than 20 and because it's decreasing.
In a regular for loop, the first number must be less than the second. In a decreasing for loop, the first number must be greater than the second.
You have a decreasing for loop in which the first number is less than the second. Switch them.
mike200015




PostPosted: Sat Mar 12, 2005 7:53 pm   Post subject: (No subject)

you also need to make the 1st for loop start at 1.. since u used locate (x,y) and the x is the for loop that starts at 0, and there is no row 0, so it needs to start at 1
ssr




PostPosted: Sat Mar 12, 2005 8:37 pm   Post subject: (No subject)

if u want, use locatexy
and yes, whenever turing sees a decreasing thats the other way, it will automatically stop/ 8)
Token




PostPosted: Sat Mar 12, 2005 8:44 pm   Post subject: (No subject)

so the code would be
code:

for x : 1 .. 20
    for decreasing y : 20 .. 1
        locate (x, y)
        put x
    end for
end for

but if u wanted the numbers to start at 0, you would have to do this



code:

for x : 1 .. 21
    for decreasing y : 20 .. 1
        locate (x, y)
        put x - 1
    end for
end for
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  [ 5 Posts ]
Jump to:   


Style:  
Search: