how to repeat an input question

8 次查看(过去 30 天)
Alex Skantz
Alex Skantz 2021-10-22
Hi, I am trying to create a loop where someone is asked to input a sentence. I need them to keep typing sentences until they eventually type a word that will terminate the loop (such as 'END') How can I do this? Here is what I have so far.
I am an absolute beginner to Matlab and am having a lot of trouble comprehending the language of coding.
N=input('what is N?: ') %establishes N
A=input('give me a sentence!: ','s'); %asks user for sentence input

回答(2 个)

KSSV
KSSV 2021-10-22
A = 'start' ;
while ~strcmpi(A,'end')
N=input('what is N?: ') %establishes N
A=input('give me a sentence!: ','s'); %asks user for sentence input
end

Walter Roberson
Walter Roberson 2021-10-22
all_A = {};
while true
A = input('give me a sentence!: ','s'); %asks user for sentence input
if strcmpi(strtrim(A), 'end'); break; end
all_A{end+1} = A;
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by