フィルターのクリア

return to a previous statement

26 ビュー (過去 30 日間)
Ace_ventura
Ace_ventura 2015 年 3 月 27 日
コメント済み: Image Analyst 2020 年 11 月 26 日
Guys,in my code I have assigned some values to certain variables and then I did some analysis.The results of analysis, are then checked for some conditions.When the condition is not met, the values will have to be re assigned.My confusion is ,how to go back to the line where values have to be assigned. eg
a=value1 ;b=value2;
%analysis
if (condition)
% code
else %go back to the statement where new values will be assigned i.e at beginning
end
  1 件のコメント
shalvi singh
shalvi singh 2019 年 1 月 8 日
Hello guys,In my code I have assigned some values to the variables and did analysis and then checked for one variable.If condition met with condition1 then I wanted to assign some statement to a variable and if met with condition2 then wanted to assign some other statement and after both if statements I wanted to run the code from starting,eg;
X=1;Y=1;
%Analysis
if (condition1)
statement1(%go back to starting of the code)
elseif (condition)
statement2(%go back to starting of the code)
end

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2015 年 3 月 27 日
編集済み: James Tursa 2015 年 3 月 27 日
while( true )
a = value1; b = value2;
% analysis
if( condition )
% code
break
end
end
If the condition is met, the code will break out of the while loop.
If the condition is not met, the code will automatically loop back to the beginning of the while loop.
Note: This loop construct is typically known as a DO-UNTIL loop.
  5 件のコメント
Abel Z
Abel Z 2020 年 11 月 26 日
break doens't work on " if %condition " loop that's my problem...
Image Analyst
Image Analyst 2020 年 11 月 26 日
Post your code in a new question.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by