Ugly number dp question issue

the above is the program to find the nth ugly number
an ugly number is a number whose prime factorisation contains only 2,3, or 5 .
the program is running infinitely what is the mistake in the program?