Truth be told, you usually don’t have to for loop in jinja templates. In the cases when you do its a bit annoying. You need to use namespaces to capture state that can then be used outside the loop. I’d recommend reading HA’s guide on templating if you haven’t yet. Also Jinja has quite detailed docs, the list of built-in tests and filters is a particularly handy reference.
Also for the particular use case of managing updates, I think you may find this helpful.