Using switch-case. Return to beginning of switch-case statement

2 ビュー (過去 30 日間)
Andy
Andy 2013 年 1 月 26 日
Essentially, I'd like the user to input a number 0-3.
i.e.
A = input ('Enter a number (0-3)');
switch A case 0 %Do something case 1 %Do something else case 2 %Do something else case 3 %Do something else otherwise %Invalid number.
end
So, in the otherwise statement, how would I go about returning to the beginning of the switch? So that one would not have to run the program again?

採用された回答

Cedric
Cedric 2013 年 1 月 26 日
編集済み: Cedric 2013 年 1 月 26 日
You don't even need otherwise ..
isOk = false ;
while ~isOk
A = input ('Enter a number (0-3)');
switch A
case 0
isOk = true ;
% do something..
case 1
isOk = true ;
% do something..
case 2
isOk = true ;
% do something..
end
end
  1 件のコメント
Andy
Andy 2013 年 1 月 26 日
Oh, thanks. I'll try this.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by