Mercurial > octave-nkf
comparison doc/interpreter/stmt.txi @ 3489:cbee5fbb696d
[project @ 2000-01-28 09:14:32 by jwe]
author | jwe |
---|---|
date | Fri, 28 Jan 2000 09:14:34 +0000 |
parents | 9610d364e444 |
children | aae05d51353c |
comparison
equal
deleted
inserted
replaced
3488:85c0ebb78d1e | 3489:cbee5fbb696d |
---|---|
33 | 33 |
34 @menu | 34 @menu |
35 * The if Statement:: | 35 * The if Statement:: |
36 * The switch Statement:: | 36 * The switch Statement:: |
37 * The while Statement:: | 37 * The while Statement:: |
38 * The do-until Statement:: | |
38 * The for Statement:: | 39 * The for Statement:: |
39 * The break Statement:: | 40 * The break Statement:: |
40 * The continue Statement:: | 41 * The continue Statement:: |
41 * The unwind_protect Statement:: | 42 * The unwind_protect Statement:: |
42 * The try Statement:: | 43 * The try Statement:: |
291 using a jump table. | 292 using a jump table. |
292 @end itemize | 293 @end itemize |
293 | 294 |
294 @DOCSTRING(warn_variable_switch_label) | 295 @DOCSTRING(warn_variable_switch_label) |
295 | 296 |
296 @node The while Statement, The for Statement, The switch Statement, Statements | 297 @node The while Statement, The do-until Statement, The switch Statement, Statements |
297 @section The @code{while} Statement | 298 @section The @code{while} Statement |
298 @cindex @code{while} statement | 299 @cindex @code{while} statement |
299 @cindex @code{endwhile} statement | 300 @cindex @code{endwhile} statement |
300 @cindex loop | 301 @cindex loop |
301 @cindex body of a loop | 302 @cindex body of a loop |
363 simple. | 364 simple. |
364 | 365 |
365 @xref{The if Statement}, for a description of the variable | 366 @xref{The if Statement}, for a description of the variable |
366 @code{warn_assign_as_truth_value}. | 367 @code{warn_assign_as_truth_value}. |
367 | 368 |
368 @node The for Statement, The break Statement, The while Statement, Statements | 369 @node The do-until Statement, The for Statement, The while Statement, Statements |
370 @section The @code{do-until} Statement | |
371 @cindex @code{do-until} statement | |
372 | |
373 The @code{do-until} statement is similar to the @code{while} statement, | |
374 except that it repeatedly executes a statement until a condition becomes | |
375 true, and the test of the condition is at the end of the loop, so the | |
376 body of the loop is always executed at least once. As with the | |
377 condition in an @code{if} statement, the condition in a @code{do-until} | |
378 statement is considered true if its value is non-zero, and false if its | |
379 value is zero. If the value of the conditional expression in a | |
380 @code{do-until} statement is a vector or a matrix, it is considered | |
381 true only if @emph{all} of the elements are non-zero. | |
382 | |
383 Octave's @code{do-until} statement looks like this: | |
384 | |
385 @example | |
386 @group | |
387 do | |
388 @var{body} | |
389 until (@var{condition}) | |
390 @end group | |
391 @end example | |
392 | |
393 @noindent | |
394 Here @var{body} is a statement or list of statements that we call the | |
395 @dfn{body} of the loop, and @var{condition} is an expression that | |
396 controls how long the loop keeps running. | |
397 | |
398 This example creates a variable @code{fib} that contains the first ten | |
399 elements of the Fibonacci sequence. | |
400 | |
401 @example | |
402 @group | |
403 fib = ones (1, 10); | |
404 i = 2; | |
405 do | |
406 i++; | |
407 fib (i) = fib (i-1) + fib (i-2); | |
408 until (i == 10) | |
409 @end group | |
410 @end example | |
411 | |
412 A newline is not required between the @code{do} keyword and the | |
413 body; but using one makes the program clearer unless the body is very | |
414 simple. | |
415 | |
416 @xref{The if Statement}, for a description of the variable | |
417 @code{warn_assign_as_truth_value}. | |
418 | |
419 @node The for Statement, The break Statement, The do-until Statement, Statements | |
369 @section The @code{for} Statement | 420 @section The @code{for} Statement |
370 @cindex @code{for} statement | 421 @cindex @code{for} statement |
371 @cindex @code{endfor} statement | 422 @cindex @code{endfor} statement |
372 | 423 |
373 The @code{for} statement makes it more convenient to count iterations of a | 424 The @code{for} statement makes it more convenient to count iterations of a |