Strcmpi and while loop in a script

Day=strcmpi('monday', 'monday')=1
Day=strcmpi('monday', 'friday')=0
answer=input('favorite day?' , 's')
Thanks to any help

 採用された回答

Amit
Amit 2014 年 1 月 19 日

0 投票

tf = 0;
comp_fav_day = 'monday'; %Lets say
while (tf == 0)
answer=input('favorite day?\n' , 's');
tf = strcmpi(comp_fav_day,answer);
end

5 件のコメント

Amit
Amit 2014 年 1 月 19 日
btw, when you get the answer from a user that works for you, you should 'accept that answer'
Riri
Riri 2014 年 1 月 20 日
Can you tell me what does tf mean ?
Amit
Amit 2014 年 1 月 20 日
tf is just a flag that switches to 1 when both strings matches.
Riri
Riri 2014 年 1 月 20 日
can I use any other variable as a flag like a=0 while a==0
Amit
Amit 2014 年 1 月 21 日
Yup. You can change tf to any variable name you want.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2014 年 1 月 19 日

編集済み:

2014 年 1 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by