I have this code in a function, but when it runs it does a long pause and then it says:
$floating point exception
I am assuming this is due to
Once you set j to 1 the loop will go on forever. If you want to stop the loop when the if condition is true use break.
j
if
break