How to loop in receipt?

Can someone teach me on how to do this??
Its part of a receipt im working on

Press 1 if continue shopping, otherwise, press 2: 1
Enter product number: 2
Enter quantity: 4
Press 1 if continue shopping, otherwise, press 2: 1
Enter product number: 5
Enter quantity: 3
Press 1 if continue shopping, otherwise, press 2: 2

Hi there, welcome to the forums.

I won’t give you the answer outright… but I’ll give you a nudge in the right direction.

  1. Two common types of loop in Java are the for loop and the while loop. Can you think of a way to use one of these to keep a set block of code running until a specific condition is met?

  2. Can you think of another control flow pattern which you could use inside the loop to control when to stop this loop?

Hopefully that’s not too cryptic. :slight_smile: