Computer Science Canada

How can I have the FOR LOOP output what loop it is on..?....

Author:  HelloWorld [ Tue Nov 09, 2004 6:18 pm ]
Post subject:  How can I have the FOR LOOP output what loop it is on..?....

How can I have the FOR LOOP output what loop it is on..?....

I need my FOR LOOP to output which loop it is on so I can state which part number it is...

code:

    for counter : 1 .. n

        put "", skip
        put "PART", n %?? How can I do this?
        put "What is the part number? " ..
        get part (counter)

        put "How many of this part were purchased? " ..
        get quantity (counter)

        put "What is the parts name? " ..
        get pname (counter) : *

        put "What is the Net price of this part? " ..
        get netprice (counter)

        put "What is the Unit price for this part? " ..
        get price (counter)

    end for


Can anyone help me out with this? Thanks.

Author:  wtd [ Tue Nov 09, 2004 6:24 pm ]
Post subject:  Re: How can I have the FOR LOOP output what loop it is on..?

HelloWorld wrote:
How can I have the FOR LOOP output what loop it is on..?....

I need my FOR LOOP to output which loop it is on so I can state which part number it is...

code:

    for counter : 1 .. n

        put "", skip
        put "PART", n %?? How can I do this?
        put "What is the part number? " ..
        get part (counter)

        put "How many of this part were purchased? " ..
        get quantity (counter)

        put "What is the parts name? " ..
        get pname (counter) : *

        put "What is the Net price of this part? " ..
        get netprice (counter)

        put "What is the Unit price for this part? " ..
        get price (counter)

    end for


Can anyone help me out with this? Thanks.


The "counter" variable is already doing that for you.

Author:  HelloWorld [ Tue Nov 09, 2004 6:35 pm ]
Post subject: 

Ha, sorry, I really should think harder before asking questions. Thanks though, it was easy (counter : n)...

Author:  HelloWorld [ Tue Nov 09, 2004 6:38 pm ]
Post subject: 

Actually, I still have a problem, when I use:

code:

put "PART", counter : n


It works well, but depending on the value of 'n', it spaces out "PART" and the number.... like the higher the value of 'n' the more spaces there are between "PART" and the number.... How can I keep it just one spacing?

Author:  Hikaru79 [ Tue Nov 09, 2004 6:44 pm ]
Post subject: 

Remember, Letters are Left-aligned, numbers are right-aligned. As n increases, the "counter" has a larger field space to itself; and since it's at the right side of the field, it'll be farther away from "Part". For just ONE space, use:

code:

put "Part ", counter

Author:  HelloWorld [ Tue Nov 09, 2004 6:49 pm ]
Post subject: 

Thanks for the help. And by the way......

Quote:

Letters are Left-aligned, numbers are right-aligned


I didn't know that, thanks again for the new knowledge!


: