Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
I realise this is a very basic question but I am only in my first couple of weeks of my programming course. I have spent ages trying to figure out the answer to this question.
orders_to_deliver = 10 meals_per_order = 5 while orders_to_deliver > 0 while meals_per_order > 5 make_meal meals_per_order -= 1 endwhile deliver_order orders_to_deliver -= 1 endwhile
How would you change this code to make exactly 30 meals, with 5 for each order? (Hint: Set meals_per_order back to 5 after meals after the while loop).
I’m guessing you need to reset the meals_per_order variable to 5 but then I am stuck as to how I get the while loop to execute again before moving on to the deliver loop.
Thanks in advance.
I am stuck as to how I get the while loop to execute again before moving on to the deliver loop.
It’s a while loop nested inside a while loop. The inner while loop is already executing again. All you have to do is reset
meals_per_order to 5 somewhere outside the inner loop but inside the outer loop. That way it’ll be reset once per outer loop iteration.
There are many places you could do that. My personal favorite would be to just swap lines 2 and 3.
Not the answer you’re looking for? Browse other questions tagged pseudocode or ask your own question.