diff doc/interpreter/var.txi @ 4686:c7ae43dfdea4

[project @ 2004-01-06 19:29:23 by jwe]
author jwe
date Tue, 06 Jan 2004 19:31:57 +0000
parents f6a61399bc5c
children c8368716bab3
line wrap: on
line diff
--- a/doc/interpreter/var.txi	Tue Jan 06 17:20:55 2004 +0000
+++ b/doc/interpreter/var.txi	Tue Jan 06 19:31:57 2004 +0000
@@ -55,6 +55,7 @@
 
 @menu
 * Global Variables::            
+* Persistent Variables::        
 * Status of Variables::         
 * Summary of Built-in Variables::  
 * Defaults from the Environment::  
@@ -154,6 +155,47 @@
 
 @DOCSTRING(isglobal)
 
+@node Persistent Variables
+@section Persistent Variables
+@cindex persistent variables
+@cindex @code{persistent} statement
+@cindex variables, persistent
+
+A variable that has been declared @dfn{persistent} within a function
+will retain its contents in memory between subsequent calls to the
+same function. The difference between persistent variables and global
+variables is that persistent variables are local in scope to a
+particular function and are not visible elsewhere.
+
+A variable may be declared persistent using a @code{persistent}
+declaration statement.  The following statements are all persistent
+declarations.
+
+@example
+@group
+persistent a
+persistent a b
+persistent c = 2
+persistent d = 3 e f = 5
+@end group
+@end example
+
+The behavior of persistent variables is equivalent to the behavior of
+static variables in C. The command @code{static} in octave is also
+recognized and is equivalent to @code{persistent}. Unlike global
+variables, every initialization statement will re-initialize the
+variable. For example, after executing the following code
+
+@example
+@group
+persistent pvar = 1
+persistent pvar = 2
+@end group
+@end example
+
+@noindent
+the value of the persistent variable @code{pvar} is 2.
+
 @node Status of Variables
 @section Status of Variables