How to write a do...while loop. Use a do...while loop to run the same block of code while a specified condition is true. This loop will always be executed once, even if the condition is false, because the statements are executed before the condition is tested.