`while` loops run as long as a condition holds. `break` exits the loop immediately; `continue` skips to the next iteration.
python
n = 10
steps = 0
while n != 1:
n = n // 2 if n % 2 == 0 else 3 * n + 1
steps += 1A `for`/`while` can have an `else` clause that runs only if the loop completes without `break` — useful for search patterns:
python
for tx in txs:
if tx.get("suspicious"):
break
else:
print("no suspicious tx found")