필터 지우기
필터 지우기

IF loop end if

조회 수: 2 (최근 30일)
James
James 2013년 6월 26일
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.

답변 (1개)

David Sanchez
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
David Sanchez 2013년 6월 26일
break only works with while and for loops, it has no effect on if conditions.
David Sanchez
David Sanchez 2013년 6월 26일
break will terminate the closest for/_while_ loop.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by