How to stop the for loop once the right input is given. Cannot use break.
Show older comments
n=3;
for i=1:n
riddle2prompt='I dont have eyes, but once I did see. Once I had thoughts, but now Im white and empty. What am I? ';
riddle2=input(riddle2prompt,'s');
if strcmpi(riddle2,'Skull')
%Asking the final riddle because the user answered the other two right.
fprintf('\n')
fprintf('*sighs* You arent supposed to get these. Your final riddle is;')
fprintf('\n')
else
%The game ends if answer is wrong.
fprintf('What did I say about not messing up. Get it right, %s!',name)
fprintf('\n')
fprintf('You have 2 more tries.')
fprintf('\n')
if i==2
fprintf('Haha, you only have 1 more tries. Careful.')
fprintf('\n')
fprintf('Your hint for this riddle is; your brain makes its home here.')
fprintf('\n')
end
if i==3
fprintf('Oh no, what did I say. Now youve already failed my game.')
fprintf('\n')
fprintf('Its GAME OVER for you!!')
riddles=false;
end
end %End to an if statement
end
How do I end the for loop if the user answers the riddle correctly, I dont want to use break for this.
Is there another way to do it??
Accepted Answer
More Answers (0)
Categories
Find more on Video games 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!