Use a 'while loop' when the number of iterations isn't known upfront.
A 'while loop' continues to execute as long as a condition is true. It's useful for reading through a list until a certain condition is met, like processing cart items until a specific product is found. For instance, while(index < cartItems.length) { // do something with cartItems[index]; index++; }.