Push up and down
This can result in fewer checks overall, centralizing control flow in a single function, and making it easier to notice redundancies and dead conditions for code quality and performance
Push Ifs Up And Fors Down
A short note on two related rules of thumb.
https://matklad.github.io/2023/11/15/push-ifs-up-and-fors-down.html
Seonglae Cho