MATLAB: While loop ends before the question is answered

while loop

r=randi(51)+49;
%the random integer generator will give a number inbetween 50 nad 100 for the user to guess.
disp('I''m thinking of a number between 50 and 100. Can you guess what it is?')
disp('I''m going to have you guess the number and I''ll let you know if it''s right.')
disp(' ')
disp('What is you''re guess')
user_number=input('Please input your number here: ');
clc
%laying the ground rules for the game, so it is clear and easy to understand.
disp('Here''s your guess:')
disp(user_number)
%Making the answer placement more appearent.
count=0;
numguess=0;
chance=0;
while r>=50 || r<=100
r=r;
if user_number==r
disp('Nice job you guessed the right number!')
elseif user_number>r;
disp('You guess is too high. try again.')
user_number=input('enter new guess here');
elseif user_number<r;
disp('Your guessed the wrong number. try again.')
user_number=input('enter new guess here');
end
break
end
%I'm strugling to find a way to continues the loop when the question is asked wrong.

Best Answer

Your break is in the wrong place. It should be under one of the if conditions:
if user_number==r
disp('Nice job you guessed the right number!')
break
And you might give the user better feedback if the guess is too low:
elseif user_number<r;
disp('Your guess is too low. try again.')