hi,
i have a very complex code. but the simplified version is this-
x=10
while x>3
for i=1:10
%some task which reduces the value of x, lets say
x=x-1
end
end
so basically what i want is that i want to get out of the while loop when x becomes less than 4. but matlab runs the for loop 10 times. i want matlab to run the for loop for 7 times. how do i do this?

1 件のコメント

rajesh kumar
rajesh kumar 2018 年 5 月 23 日
give x=x-1 outside the for loop

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

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 23 日
編集済み: Ameer Hamza 2018 年 5 月 23 日

0 投票

add inside for loop
if x==3 % or if x < 4
break
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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