while not finished: do_work()
Iteration Patterns

Meaning

Repeatedly executes do_work() while the condition 'not finished' evaluates to True, i.e., repeats the action until finished becomes True.

Primary Function

Repeated execution of a statement until a condition becomes false (loop until condition changes).

Communicative Purpose

Expresses repetition until a condition becomes true; conveys ongoing activity until a goal is reached.

Pattern

while not <condition>: <statement>

Core Structure

while not <condition>: <statement>

Função primária

Repeated execution of a statement until a condition becomes false (loop until condition changes).

Propósito comunicativo

Expresses repetition until a condition becomes true; conveys ongoing activity until a goal is reached.

Situações de gatilho

Used when an action must be repeated until a certain state is reached, such as polling for completion, waiting for user input, or processing items until a queue is empty.

Contextos

Polling loops, game loops, waiting for external events, processing batches until empty.

Padrão

while not <condition>: <statement>

Estrutura central

while not <condition>: <statement>

Slots de substituição

<condition>: boolean expression; <statement>: statement or block to repeat.

Colocados típicos

  • finished
  • done
  • ready
  • exit
  • flag
  • done_flag

Substituições comuns

  • condition variable (e.g.
  • not done
  • not ready
  • not exit)
  • action statement (e.g.
  • do_work()
  • process_item()
  • read_input())

Erros comuns

Failing to update the condition inside the loop causing infinite loop; using assignment (=) instead of comparison (==) in condition; incorrect indentation; confusing 'while not' with 'while' (inverted logic).

Similar / contraste

while finished: (loop while true), while True: with break when condition met, until loop (in some languages) which repeats until condition true.

Interferências

Confusing 'while not' with 'while' (negation confusion); accidental infinite loops if condition never changes.

Família do chunk

  • while-loop patterns

Nuance

Expresses a busy-wait or polling loop; assumes condition will eventually become true; may consume CPU unless combined with sleep or delay.

Efeito pragmático

Communicates persistent effort until a goal is achieved; conveys expectation of eventual termination.

Dica de memória

Keep working until finished.

Nota

Common polling idiom; ensure the condition is updated inside the loop to avoid infinite spinning.

Upgrade path

Consider using event‑driven callbacks or async/await instead of busy‑wait loops for better efficiency.

Frequência: Very highFormulaicidade: Semi-fixedTipo de construção: while loopPrioridade de aquisição: Automatic productionPrioridade de output: BothTag de espaçamento: Immediate

Log in to save chunks.