Return to the start of while or continue the script with an if condition
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi, I have a while loop. Inside this loop I want to put an If condition, if true then return to the start of the while loop, if false then continue with the loop:
while i<j
a=rand
if a<0.5
i=i+1
disp('try again')
% and there I want to return to start of while loop
else
disp('continue')
% and there I want to continue with 'more code' section
end
% more code
end
Thanks in advance.
댓글 수: 0
채택된 답변
Geoff Hayes
2022년 6월 6일
편집: Geoff Hayes
2022년 6월 6일
while i<j
a=rand
if a<0.5
i=i+1
disp('try again')
continue;
end
disp('continue')
% more code
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
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!