# HG changeset patch # User jwe # Date 1179774766 0 # Node ID c18ed0e7ee41641a25483031e6438752b31d8656 # Parent de8a8ba43848f97450c400613080cc4f82344be2 [project @ 2007-05-21 19:12:46 by jwe] diff -r de8a8ba43848 -r c18ed0e7ee41 doc/ChangeLog --- a/doc/ChangeLog Sat May 19 19:07:55 2007 +0000 +++ b/doc/ChangeLog Mon May 21 19:12:46 2007 +0000 @@ -1,3 +1,8 @@ +2007-05-21 Søren Hauberg + + * interpreter/stmt.txi: Describe cell array cases for the switch + statement. Minor layout changes. + 2007-05-19 David Bateman * interpreter/func.txi: Additional documentation for function diff -r de8a8ba43848 -r c18ed0e7ee41 doc/interpreter/stmt.txi --- a/doc/interpreter/stmt.txi Sat May 19 19:07:55 2007 +0000 +++ b/doc/interpreter/stmt.txi Mon May 21 19:12:46 2007 +0000 @@ -71,8 +71,8 @@ The condition in an @code{if} statement is considered true if its value is non-zero, and false if its value is zero. If the value of the conditional expression in an @code{if} statement is a vector or a -matrix, it is considered true only if @emph{all} of the elements are -non-zero. +matrix, it is considered true only if it is non-empty and @emph{all} +of the elements are non-zero. The second form of an if statement looks like this: @@ -262,6 +262,21 @@ @code{case @var{label} @var{command_list}} clause must be present, while the @code{otherwise @var{command_list}} clause is optional. +If @var{label} is a cell array the corresponding @var{command_list} +is executed if @emph{any} of the elements of the cell array match +@var{expression}. As an example, the following program will print +@samp{Variable is either 6 or 7}. + +@example +A = 7; +switch A + case @{ 6, 7 @} + printf ("variable is either 6 or 7\n"); + otherwise + printf ("variable is neither 6 nor 7\n"); +endswitch +@end example + As with all other specific @code{end} keywords, @code{endswitch} may be replaced by @code{end}, but you can get better diagnostics if you use the specific forms. @@ -297,14 +312,14 @@ @node Notes for the C programmer @subsection Notes for the C programmer -The @code{switch} statement is also used in the widely used C +The @code{switch} statement is also available in the widely used C programming language. There are, however, some differences between the statement in Octave and C @itemize @bullet @item Cases are exclusive, so they don't `fall through' as do the cases -in the switch statement of the C language. +in the @code{switch} statement of the C language. @item The @var{command_list} elements are not optional. Making the list @@ -333,7 +348,18 @@ @end example @noindent -particularly for C programmers. +particularly for C programmers. If @code{doit()} should be executed if +@var{foo} is either @code{1} or @code{2}, the above code should be +written with a cell array like this + +@example +@group +switch (foo) + case @{ 1, 2 @} + doit (); + @dots{} +@end group +@end example @end itemize @node The while Statement @@ -352,7 +378,7 @@ @code{while} statement is considered true if its value is non-zero, and false if its value is zero. If the value of the conditional expression in a @code{while} statement is a vector or a matrix, it is considered -true only if @emph{all} of the elements are non-zero. +true only if it is non-empty and @emph{all} of the elements are non-zero. Octave's @code{while} statement looks like this: @@ -417,7 +443,7 @@ statement is considered true if its value is non-zero, and false if its value is zero. If the value of the conditional expression in a @code{do-until} statement is a vector or a matrix, it is considered -true only if @emph{all} of the elements are non-zero. +true only if it is non-empty and @emph{all} of the elements are non-zero. Octave's @code{do-until} statement looks like this: @@ -473,7 +499,7 @@ @var{expression} is any valid expression, and @var{var} may take several forms. Usually it is a simple variable name or an indexed variable. If the value of @var{expression} is a structure, @var{var} may also be a -list. @xref{Looping Over Structure Elements}, below. +vector with two elements. @xref{Looping Over Structure Elements}, below. The assignment expression in the @code{for} statement works a bit differently than Octave's normal assignment statement. Instead of @@ -602,7 +628,7 @@ The elements are not accessed in any particular order. If you need to cycle through the list in a particular way, you will have to use the -function @code{struct_elements} and sort the list yourself. +function @code{fieldnames} and sort the list yourself. The @var{key} variable may also be omitted. If it is, the brackets are also optional. This is useful for cycling through the values of all the @@ -735,7 +761,7 @@ @end example @noindent -Where @var{body} and @var{cleanup} are both optional and may contain any +where @var{body} and @var{cleanup} are both optional and may contain any Octave expressions or commands. The statements in @var{cleanup} are guaranteed to be executed regardless of how control exits @var{body}. @@ -756,6 +782,7 @@ @end group @end example +@noindent Without @code{unwind_protect}, the value of @var{frobnosticate} would not be restored if an error occurs while performing the indexing operation because evaluation would stop at the point of the error and @@ -782,7 +809,8 @@ @end group @end example -Where @var{body} and @var{cleanup} are both optional and may contain any +@noindent +where @var{body} and @var{cleanup} are both optional and may contain any Octave expressions or commands. The statements in @var{cleanup} are only executed if an error occurs in @var{body}. @@ -825,7 +853,7 @@ @noindent form a single statement. The backslash character on the second line -above is interpreted a continuation character, @emph{not} as a division +above is interpreted as a continuation character, @emph{not} as a division operator. For continuation lines that do not occur inside string constants, diff -r de8a8ba43848 -r c18ed0e7ee41 src/ChangeLog --- a/src/ChangeLog Sat May 19 19:07:55 2007 +0000 +++ b/src/ChangeLog Mon May 21 19:12:46 2007 +0000 @@ -1,3 +1,8 @@ +2007-05-21 Søren Hauberg + + * help.cc (Fautoload): Doc fix. + * variables.cc (Fiscommand): Doc fix. + 2007-05-19 David Bateman * ov-fcn-inline.cc (Fvectorize): Doc fix. diff -r de8a8ba43848 -r c18ed0e7ee41 src/parse.y --- a/src/parse.y Sat May 19 19:07:55 2007 +0000 +++ b/src/parse.y Mon May 21 19:12:46 2007 +0000 @@ -3523,13 +3523,13 @@ Uses like\n\ \n\ @example\n\ -autoload (\"foo\", file_in_loadpth (\"bar.oct\"))\n\ +autoload (\"foo\", file_in_loadpath (\"bar.oct\"))\n\ @end example\n\ \n\ @noindent\n\ are strongly discouraged.\n\ \n\ -With no arguments, return a structure containing the curre autoload map.\n\ +With no arguments, return a structure containing the current autoload map.\n\ @seealso{PKG_ADD}\n\ @end deftypefn") { diff -r de8a8ba43848 -r c18ed0e7ee41 src/variables.cc --- a/src/variables.cc Sat May 19 19:07:55 2007 +0000 +++ b/src/variables.cc Mon May 21 19:12:46 2007 +0000 @@ -235,7 +235,7 @@ @deftypefn {Built-in Function} {} iscommand (@var{name})\n\ Return true if @var{name} is a command style function. If @var{name}\n\ is omitted, return a list of identifiers which are marked as commands with\n\ -mark_as_command.\n\ +@code{mark_as_command}.\n\ @seealso{mark_as_command, unmark_command}\n\ @end deftypefn") {