Why does this create an infinite loop if the condition is stated?