Moved short-circuiting for and in a function.