Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The symantics of for...else are immediately obvious

The code in your example is how it reads, but that's not how it works. The "obvious" reading is wrong, so it's obviously not "immediately obvious".

This is what it's actually doing:

  found = False
  for l in get_list():
    if ...:
      found = True
      break
  if not found:
    ...


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: