if and while in separate function