how to get out infinite loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
this code required to calculate the smallest multiple with uint64 format bit gets stuck on argument 45. it only displays busy . can someone explain why?
function answer = smallest_multiple (N)
limit =1e15;
for i = N:N:limit
for j = N:-1:1
if mod(i,j) ~= 0
break
end
end
if j == 1
answer =uint64(i);
break
end
end
3 comentarios
jgg
el 24 de Jun. de 2016
You break out of your loop if i is not divisible by j at any point; this means answer is not assigned in many loop iterations. This is probably not what you want to do here.
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!