how to repeat an input question

7 visualizaciones (últimos 30 días)
Alex Skantz
Alex Skantz el 22 de Oct. de 2021
Respondida: Walter Roberson el 22 de Oct. de 2021
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

Respuestas (2)

KSSV
KSSV el 22 de Oct. de 2021
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 el 22 de Oct. de 2021
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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by