Using the while loop function

How do i make a while loop to loop five times if the user does not enter the correct input?

Answers (1)

Pavel Osipov
Pavel Osipov on 5 Oct 2019
Edited: Rik on 5 Oct 2019
fa1=false;
%fa2=true;
k=0;
while k<5
k=k+1;
if fa1==false
disp('you answer is bad, try again. ');
disp('attempt = ');disp(5-k);
else
disp('you answer is good');
break;
end%if
end%while

4 Comments

Mr. Pavel, please use special button for code inserting
11Capture.PNG
See this page for a full explanation of the editing tools that are available.
Thank you, but I don't seem to have hurt you.
Baby don't hurt me

This question is closed.

Tags

Asked:

on 5 Oct 2019

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!