in reply to Re: seeking advice on loops
in thread seeking advice on loops

thank you for your input...I know you probably get asked for homework help all the time. I do want to do it myself otherwise I won't be able to go on with the rest of the book. I just feel like this program was a big jump from the chapter 6 homework

in answer to your questions:

2) is the loop something that occurs a set number of times, or should it keep occurring until a given condition changes?

the loop of user input keeps occuring - thru every loop (enter product name, enter quantity and price) the user is asked if they want to enter another product - when they answer "no" is when you leave the loop and invoke a subroutine to process the data

Thanks so much monks...I do appreciate your time

sierra

Replies are listed 'Best First'.
Re^3: seeking advice on loops
by GrandFather (Saint) on Oct 07, 2005 at 05:58 UTC

    You may like an innoculation: try working through the Tutorial exercise material here. You might like to look at some of the other tutorial material too. Look for "Getting Started with Perl" here.


    Perl is Huffman encoded by design.
Re^3: seeking advice on loops
by jZed (Prior) on Oct 07, 2005 at 18:04 UTC
    Ok, since you've said that the user input needs to happen repeatedly, that tells you that you want the user input to happen inside a loop. Since you've said that you want to keep looping *while* a certain condition isn't met (the user says 'no'), that tells you that you want a while loop.

    Personally I like to use psuedo-code - something that is half-way between English (or whatever your native tongue) and code - and then gradually replace the pseudo-code with real code. Here's how I'd start with your assignment:

        user_wants_to_continue is 'yes'
        while ( user_wants_to_continue is not 'no' ) {
            prompt for and get product_name
            prompt for and get quantity
            prompt for and get price
            store product_name in array
            store product_name, quantity, price in hash
            prompt for and get user_wants_to_continue
         }