Computer Science Canada

y doesnt this have an output??

Author:  person [ 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]

Author:  Cervantes [ Sat Mar 12, 2005 7:48 pm ]
Post 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.

Author:  mike200015 [ Sat Mar 12, 2005 7:53 pm ]
Post 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

Author:  ssr [ Sat Mar 12, 2005 8:37 pm ]
Post subject: 

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

Author:  Token [ Sat Mar 12, 2005 8:44 pm ]
Post 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


: