Trying to get a conditional loop to work with while and if statements