comparison doc/interpreter/stmt.txi @ 9209:923c7cb7f13f

Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction. spellchecked all .txi and .texi files.
author Rik <rdrider0-list@yahoo.com>
date Sun, 17 May 2009 12:18:06 -0700
parents fca0dc2fb042
children 322f43e0e170
comparison
equal deleted inserted replaced
9208:cb163402bf79 9209:923c7cb7f13f
218 It is very common to take different actions depending on the value of 218 It is very common to take different actions depending on the value of
219 one variable. This is possible using the @code{if} statement in the 219 one variable. This is possible using the @code{if} statement in the
220 following way 220 following way
221 221
222 @example 222 @example
223 @group
223 if (X == 1) 224 if (X == 1)
224 do_something (); 225 do_something ();
225 elseif (X == 2) 226 elseif (X == 2)
226 do_something_else (); 227 do_something_else ();
227 else 228 else
228 do_something_completely_different (); 229 do_something_completely_different ();
229 endif 230 endif
231 @end group
230 @end example 232 @end example
231 233
232 @noindent 234 @noindent
233 This kind of code can however be very cumbersome to both write and 235 This kind of code can however be very cumbersome to both write and
234 maintain. To overcome this problem Octave supports the @code{switch} 236 maintain. To overcome this problem Octave supports the @code{switch}
235 statement. Using this statement, the above example becomes 237 statement. Using this statement, the above example becomes
236 238
237 @example 239 @example
240 @group
238 switch (X) 241 switch (X)
239 case 1 242 case 1
240 do_something (); 243 do_something ();
241 case 2 244 case 2
242 do_something_else (); 245 do_something_else ();
243 otherwise 246 otherwise
244 do_something_completely_different (); 247 do_something_completely_different ();
245 endswitch 248 endswitch
249 @end group
246 @end example 250 @end example
247 251
248 @noindent 252 @noindent
249 This code makes the repetitive structure of the problem more explicit, 253 This code makes the repetitive structure of the problem more explicit,
250 making the code easier to read, and hence maintain. Also, if the 254 making the code easier to read, and hence maintain. Also, if the
281 is executed if @emph{any} of the elements of the cell array match 285 is executed if @emph{any} of the elements of the cell array match
282 @var{expression}. As an example, the following program will print 286 @var{expression}. As an example, the following program will print
283 @samp{Variable is either 6 or 7}. 287 @samp{Variable is either 6 or 7}.
284 288
285 @example 289 @example
290 @group
286 A = 7; 291 A = 7;
287 switch A 292 switch A
288 case @{ 6, 7 @} 293 case @{ 6, 7 @}
289 printf ("variable is either 6 or 7\n"); 294 printf ("variable is either 6 or 7\n");
290 otherwise 295 otherwise
291 printf ("variable is neither 6 nor 7\n"); 296 printf ("variable is neither 6 nor 7\n");
292 endswitch 297 endswitch
298 @end group
293 @end example 299 @end example
294 300
295 As with all other specific @code{end} keywords, @code{endswitch} may be 301 As with all other specific @code{end} keywords, @code{endswitch} may be
296 replaced by @code{end}, but you can get better diagnostics if you use 302 replaced by @code{end}, but you can get better diagnostics if you use
297 the specific forms. 303 the specific forms.
311 string will be made instead of evaluating if the strings are equal. 317 string will be made instead of evaluating if the strings are equal.
312 This special-case is handled by the @code{switch} statement, and it 318 This special-case is handled by the @code{switch} statement, and it
313 is possible to write programs that look like this 319 is possible to write programs that look like this
314 320
315 @example 321 @example
322 @group
316 switch (X) 323 switch (X)
317 case "a string" 324 case "a string"
318 do_something 325 do_something
319 @dots{} 326 @dots{}
320 endswitch 327 endswitch
328 @end group
321 @end example 329 @end example
322 330
323 @menu 331 @menu
324 * Notes for the C programmer:: 332 * Notes for the C programmer::
325 @end menu 333 @end menu
579 @end group 587 @end group
580 @end example 588 @end example
581 589
582 @noindent 590 @noindent
583 In the above case, the multidimensional matrix @var{c} is reshaped to a 591 In the above case, the multidimensional matrix @var{c} is reshaped to a
584 two dimensional matrix as @code{reshape (c, rows(c), 592 two-dimensional matrix as @code{reshape (c, rows(c),
585 prod(size(c)(2:end)))} and then the same behavior as a loop over a two 593 prod(size(c)(2:end)))} and then the same behavior as a loop over a two
586 dimensional matrix is produced. 594 dimensional matrix is produced.
587 595
588 Although it is possible to rewrite all @code{for} loops as @code{while} 596 Although it is possible to rewrite all @code{for} loops as @code{while}
589 loops, the Octave language has both statements because often a 597 loops, the Octave language has both statements because often a