Repeat until

2 snippets across 2 stacks — JavaScript, Python

JSJavaScript

while and do...while

JS · Control Flow
syntax
while (condition) { ... }
do { ... } while (condition);
example
// Retry until success (with limit)
let attempts = 0;
let success = false;
while (!success && attempts < 5) {
  attempts++;
  success = Math.random() > 0.7;
}
console.log(`Succeeded after ${attempts} attempt(s): ${success}`);

// do...while always runs at least once
let input;
do {
  input = prompt("Enter a number > 10:");
} while (Number(input) <= 10);

Note do...while guarantees at least one iteration. Useful for retry logic and input validation loops.

PYPython

while Loops

PY · Control Flow
syntax
while condition:
    ...
example
attempts = 0
max_attempts = 3

while attempts < max_attempts:
    attempts += 1
    print(f"Try {attempts}")

print("Done")
output
Try 1
Try 2
Try 3
Done

Note Make sure the condition eventually becomes False; otherwise you get an infinite loop. Use Ctrl+C to interrupt a runaway loop.