i can't get my while loop to work
Show older comments
i need this while loop to work but it just keep auto repeating isntead of asking the question to the user
RunAgain == 1
while RunAgain == 1
%my code
RunAgain = input ('\nWould you like to run this again?(1 for yes 0 for no)? ');
while isempty (RunAgain) == 1 || RunAgain ~= 1 && RunAgain ~= 0
RunAgain = input ('\nERROR, Would you like to run this again?(1 for yes 0 for no)? \n ');
end
if you could keep it in this format that would be great! i think the problem in where the double && sign is but im not sure what or how to change it
2 Comments
KSSV
on 3 May 2022
What exactly uou want to do? isempty (RunAgain) == 1, this could be simply isempty(RunAgain).
Riley Phillips
on 3 May 2022
Answers (1)
Walter Roberson
on 3 May 2022
while ~(isequal(RunAgain, 0) || isequal(RunAgain, 1))
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!