escaping infinite loop and return previous step automatically?

5 ビュー (過去 30 日間)
sermet
sermet 2013 年 1 月 4 日
in here, if I input 0 for a, infinite loops occurs, what I want is escaping this infinite loop and returning previous step which asking me again input a,b,c? I wonder that can matlab execute this automatically? For example after the entering 0 matlab should ask me again a,b,c? automatically.
a=input(' a =? ')
b=input(' b =?')
c=input(' c =?')
while a==0
disp(' equation is first degree, try to input another number except 0')
end
D=b^2-4*a*c
x1=( -b + sqrt(D) )/(2*a)
x2=( -b - sqrt(D) )/(2*a)
if D < 0
disp(...........')
x1
x2
else if D == 0
disp(...........')
x1,x2
else
disp(.............')
x1
x2
end
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 1 月 4 日
編集済み: Walter Roberson 2013 年 1 月 4 日
a = 0;
while a==0
a=input(' a =? ')
b=input(' b =?')
c=input(' c =?')
if a == 0
disp(' equation is first degree, try to input another number except 0')
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