
-----------------------------------
redsp0t
Mon Nov 15, 2010 4:30 pm

Loop situation
-----------------------------------
Hi, I have to do a program that repeats the numbers 1 to 15 in different colours, this may be easy but I am new to this and would like some explanation on how to do this. Thank you.

-----------------------------------
TheGuardian001
Mon Nov 15, 2010 5:45 pm

Re: Loop situation
-----------------------------------
the color() method will let you set the text colour.

a for loop will let you do something 15 times, and gives you a variable to output

the put command will let you output the number.

-----------------------------------
SNIPERDUDE
Mon Nov 15, 2010 6:35 pm

RE:Loop situation
-----------------------------------
The Turing Walkthrough has plenty of information on how to use the colour and for loop commands.

-----------------------------------
redsp0t
Mon Nov 15, 2010 9:00 pm

Re: Loop situation
-----------------------------------
the color() method will let you set the text colour.

a for loop will let you do something 15 times, and gives you a variable to output

the put command will let you output the number.

Yes, thank you. But I really don't understand how to incorporate them together. And it doesn't really explain in the guide how to use different colours in a loop body. I don't think we can use colour as a counter because it is a procedure. So I need some more elaboration on this. Thanks for your time.

-----------------------------------
TheGuardian001
Mon Nov 15, 2010 9:20 pm

Re: Loop situation
-----------------------------------
the color() method will let you set the text colour.

a for loop will let you do something 15 times, and gives you a variable to output

the put command will let you output the number.
 I don't think we can use colour as a counter because it is a procedure
You don't use the colour command as a counter, you use the for loop as a counter.

create a for loop. inside of it, choose a colour (using the colour() method). now output a number. now end your loop.

-----------------------------------
Insectoid
Mon Nov 15, 2010 9:21 pm

RE:Loop situation
-----------------------------------
The color function takes an integer as a parameter. For loops pass an integer into the block. 

Got any ideas yet?

-----------------------------------
TokenHerbz
Mon Nov 15, 2010 10:40 pm

RE:Loop situation
-----------------------------------
use the for loop counter to change the colors.

-----------------------------------
redsp0t
Mon Nov 15, 2010 10:58 pm

RE:Loop situation
-----------------------------------
This is more what I was looking for, but thanks I solved my own question, which I think is better than getting the answer from someone else. Thank you all for taking the time to comment and try and help.

const DELAY := 500
const REPETITION_LIMIT := 15

var integer : int

integer := 1

loop

    colourback (integer)

    colour (0)

    put integer

    integer := integer + 1

    delay (DELAY)

    exit when integer > REPETITION_LIMIT

end loop

-----------------------------------
DemonWasp
Mon Nov 15, 2010 11:24 pm

RE:Loop situation
-----------------------------------
While it is true that it's best to build your answers than simply copy from others, you should know that what you've written there is a common pattern known as a counted loop. It is commonly solved by using for statements, though there are plenty of languages that use different means.

Your code can be shrunk to the following

const DELAY := 500 
const REPETITION_LIMIT := 15 

for integer : 1 .. REPETITION_LIMIT
    colourback (integer)
    colour (0)

    put integer

    delay (DELAY) 
end for


As you can see, the for construct removes the need for the following:
- declaring the integer variable
- incrementing the integer variable
- checking and exiting when you hit the maximum

-----------------------------------
TokenHerbz
Tue Nov 16, 2010 2:52 am

Re: Loop situation
-----------------------------------
from the OP, this should suffice. //for statement for amount of numbers, using it to also change colors of the numbers that you put down.
[code]
for i : 1 .. 15
    color (i)
    put i
end for
[/code]
