Debian Codegraph @

octave_kernel/@yes_or_no/yes_or_no.m

raw
1 ## -*- texinfo -*-
2 ## @deftypefn {Built-in Function} {@var{ans} =} yes_or_no ("@var{prompt}")
3 ## Ask the user a yes-or-no question.
4 ##
5 ## Return logical true if the answer is yes or false if the answer is no.
6 ##
7 ## Takes one argument, @var{prompt}, which is the string to display when asking
8 ## the question. @var{prompt} should end in a space; @code{yes-or-no} adds the
9 ## string @samp{(yes or no) } to it. The user must confirm the answer with
10 ## @key{RET} and can edit it until it has been confirmed.
11 ## @seealso{input}
12 ## @end deftypefn
13
14 function ans = yes_or_no(varargin)
15 if (nargin == 0)
16 varargin = {''};
17 end
18 if (nargin > 1)
19 builtin('yes_or_no', varargin{:});
20
21 else
22 prompt = strcat(varargin{1}, ' (yes_or_no) __stdin_prompt>');
23 while (1)
24 resp = input(prompt, 's');
25 if (strcmp(resp, 'yes') == 1)
26 ans = true;
27 break;
28
29 elseif (strcmp(resp, 'no') == 1)
30 ans = false;
31 break;
32
33 end;
34 prompt = 'Please answer yes or no.';
35 end;
36 end;
37
38 end;