IF loop end if
4 次查看(过去 30 天)
显示 更早的评论
FOR loop that runs i=1:N with an embedded IF loop that executes if val(i)>0 and val(i+1)<0 or opposite way around and outputs i. This works fine, but does take time.
How can I stop the FOR loop from continuing to run once it finds this value of i? What takes most running time is that it goes through the whole FOR loop range even if it finds the sign change early on.
0 个评论
回答(1 个)
David Sanchez
2013-6-26
use break after you get the desired value. It will take you out of the for loop
3 个评论
David Sanchez
2013-6-26
break only works with while and for loops, it has no effect on if conditions.
另请参阅
类别
在 Help Center 和 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!