Use a for loop when the range or iteration count is known. Its header initializes a loop variable, tests a condition and changes that variable after each iteration. A while loop checks before each repetition, so it may run zero times. A do-while loop checks afterward and always runs at least once, which counts the single digit in zero.
Every loop needs progress toward a stopping condition. Count down remaining work, increase an index or remove a digit; leaving that state unchanged can run forever. Use break when the whole loop should end and continue when only the current item should be skipped. Check the empty range, the final endpoint and an exact multiple. Those cases expose many off-by-one errors before a longer example does.