in reply to seeking advice on loops

As you'll probably find out, asking for help with homework isn't looked on too favorably here, but you've certainly been honest about it and it also sounds like you've put some work into it. Perhaps these two questions will help you find an answer: 1) is getting user input something you want to do once or many times? 2) is the loop something that occurs a set number of times, or should it keep occurring until a given condition changes? If you can answer those questions, I think you'll answer your other questions as well.

Replies are listed 'Best First'.
Re^2: seeking advice on loops
by blazar (Canon) on Oct 07, 2005 at 08:40 UTC
    As you'll probably find out, asking for help with homework isn't looked on too favorably here
    I think that what is frowned upon not only here, but probably also in any (online) Perl community is not "asking for help with homework" as much as one's asking people to do homework for him/her, especially without explicitly saying so. But sierrastar has asked for advice wrt homework, clearly stating so. In this case I think it won't be any problem giving that help...
Re^2: seeking advice on loops
by sierrastar (Sexton) on Oct 07, 2005 at 05:15 UTC

    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

      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.
      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
           }