% Demo of "mixed" loops % Initialize variables: max = 2; % max guess min = 1; % min guess target = floor(rand*(max-min+1)) + 1; % computer picked-number guess = input('Enter a value: '); % user guess count = 1; % number of guesses so far maxcount = 2; % max allowed guesses % Prompt user to guess correct number: while count < max & guess ~= target disp('Wrong!'); guess = input('Enter another value: '); % user guesses again count=count+1; end % Congratulate user: if guess==target disp('Right!'); disp(['It took ',num2str(count),' guesses.']); else disp('You took too many guesses!'); end