% NUMGUESS Script M-file for guessing.
% Demonstrate capabilities of script files.

disp('I''m thinking of a number from 1 to 10.');
secretNum = fix(10*rand + 1);  % Will be integer.

disp('Now in keyboard mode.  ''return'' continues.');
keyboard

guessed = false;  % Use "true" and "false" for logicals.

while ~guessed
  thisGuess = input('Guess, or type -1 to give up: ');
  if thisGuess == secretNum
    disp('You guessed it!  Way to go.');
    guessed = true;
    return
  elseif thisGuess == -1
    break
  else
    disp('Wrong! Try again.');
  end
end

% Only here if we "gave up".  NUM2STR displays ASCII.
disp(['You lost!  It was ' num2str(secretNum) '.']);