how to get out infinite loop
显示 更早的评论
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 个评论
Adam
2016-6-24
Why do you assume it is an infinite loop? It seems to just be very slow. Looping up to 1e15 isn't going to be especially fast.
OLUBUKOLA ogunsola
2016-6-24
jgg
2016-6-24
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.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!