Help with return to nested loop
4 ビュー (過去 30 日間)
古いコメントを表示
Hi, I need help with loops,
I have a while loop and in it I need to check input so I used nestef if
if the input is not valid it will print a msg and what I cannot seem to do is to send it beck to the beginning of the while loop to insert a different input
But whenever I try to print break or return at the end of the if, it just ends the whole function and not returns to the beggining of the loop
2 件のコメント
採用された回答
Julian Schmid
2020 年 5 月 6 日
編集済み: Julian Schmid
2020 年 5 月 6 日
From what I got you want to do something like that? It is easier to get an idea, if you provide the code you have written so far. The break or return statement does not end the if statement but the loop you are currently in.
inputArray = logical([1 0 1 0 0]); % can be strings and other numbers
nInput = length(inputArray);
ii = 1; % initialize index counter
while ii ~= nInput % nInput = number of arguments you want to check
if inputArray(ii) == false % or strcmp(inputArray(ii),'some condition') or ...
% input is wrong, display a message
disp('Something went wrong')
end
% increase counter
ii = ii + 1;
end
9 件のコメント
Image Analyst
2020 年 5 月 8 日
Maya can you then "Accept this answer" to give Julian credit (reputation points) for helping you? And also to let others know it's solved and ou've moved on. Thanks in advance.
その他の回答 (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!