boolean function for loop and while loop