how to write Conditional for loop in matlab without giving range? and it should run till condition satisfied

1 回表示 (過去 30 日間)
clear all
clc
K=0;
for Flag=1
if K>4
Flag=1
else
K=K+1
Flag=0
end
end
this should run untill Flag = 1 but its not happening it just add 1 in K and stops and gives the answer Flag=0.
i want this to run untill Flag=1.

採用された回答

Luna
Luna 2019 年 11 月 27 日
編集済み: Luna 2019 年 11 月 27 日
You should use while loop instead. Here is the link: while
Here is a sample code for your case:
K=0;
Flag = 1;
while Flag == 1
if K > 4
Flag = 0
else
K = K+1
Flag = 1
end
end

その他の回答 (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