Repeat a block of code as long as a condition is true, using `while` and `do-while` loops.
While the `for` loop is excellent for a known number of iterations, the `while` and `do-while` loops are designed for situations where the number of repetitions is uncertain and depends on a condition being met. The `while` loop is a pre-test loop. It starts with the `while` keyword, followed by a condition in parentheses. The code block (the loop body) is executed only if the condition is initially true. After each execution of the body, the condition is checked again. This process repeats as long as the condition remains true. If the condition is false to begin with, the loop body will never be executed. This makes `while` loops perfect for tasks that need to continue until a specific event occurs, such as reading data from a file until the end is reached or waiting for valid user input. The `do-while` loop is a post-test loop and a variation of the `while` loop. Its key difference is that the condition is checked at the *end* of the loop body, after it has been executed. This guarantees that the loop body will be executed at least once, regardless of whether the condition is true or false. The syntax is `do { ... } while (condition);`. This is particularly useful for scenarios like presenting a menu to a user and asking for input, where you want the menu to be displayed at least one time before checking if the user wants to quit.