pyai.docs

Foundations › 3 of 14

Control Flow

if, for, while, and Python's iteration helpers.

python
for epoch, loss in enumerate([0.9, 0.5, 0.3], start=1):
    if loss < 0.4:
        print(f"epoch {epoch}: converged")
        break

for x, y in zip(features, targets):
    ...

status = "ok" if acc > 0.9 else "retrain"
# output
epoch 3: converged
Tip: Prefer enumerate() and zip() over range(len(...)).

⚡ Quick check

  • ✓ enumerate(seq, start=1)
  • ✓ zip(a, b)
  • ✓ x if cond else y