Add a new example with resume
[scilab.git] / scilab / modules / core / help / en_US / control_flow / resume.xml
1  <?xml version="1.0" encoding="UTF-8"?>
2 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="resume">
3     <refnamediv>
4         <refname>resume</refname>
5         <refpurpose>return or resume execution and copy some local variables</refpurpose>
6     </refnamediv>
7     <refsynopsisdiv>
8         <title>Calling Sequence</title>
9         <synopsis>resume
10             [x1,..,xn]=resume(a1,..,an)
11         </synopsis>
12     </refsynopsisdiv>
13     <refsection>
14         <title>Arguments</title>
15         <variablelist>
16             <varlistentry>
17                 <term>x1,..,xn</term>
18                 <listitem>
19                     <para>variables in calling environment</para>
20                 </listitem>
21             </varlistentry>
22             <varlistentry>
23                 <term>a1,..,an</term>
24                 <listitem>
25                     <para>local variables</para>
26                 </listitem>
27             </varlistentry>
28         </variablelist>
29     </refsection>
30     <refsection>
31         <title>Description</title>
32         <para>
33             In a function <literal>resume</literal> stops the execution of the function,
34             <literal>[x1,..,xn]=resume(a1,..,an)</literal> stops the execution of the function and put the
35             local variables <literal>ai</literal> in calling environment under names
36             <literal>xi</literal>.
37         </para>
38         <para>
39             In <literal>pause</literal> mode, it allows to return to lower level
40             <literal>[x1,..,xn]=resume(a1,..,an)</literal> returns to lower level and put the local variables
41             <literal>ai</literal> in calling environment under names <literal>xi</literal>.
42         </para>
43         <para>
44             In an <literal>execstr</literal> called by a function <literal>[..]=resume(..)</literal> stops
45             the execution of the function and put the local variables 
46             <literal>ai</literal> in calling environment under names <literal>xi</literal>.
47         </para>
48         <para>
49             <literal>resume</literal> is equivalent to <literal>return</literal>.
50         </para>
51         <para>
52             <note>
53                 Note: the usage of this feature can complexify the code. Instead, the syntax <code>function b = foo()</code> is recommended.
54             </note>
55         </para>
56     </refsection>
57     <refsection>
58         <title>Examples</title>
59         <programlisting role="example"><![CDATA[
60 function foo(a)
61          a=a+1
62          b=resume(a)
63          c=52
64 endfunction
65
66 foo(42);
67 assert_checkequal(b,43);
68 // c does not exist
69
70 ]]></programlisting>
71         <programlisting role="example"><![CDATA[
72
73 // with several function calls
74 function foo1()
75   a=1;
76   b=2;
77   c=3;
78   [x,y,z]=resume(a, b, c)
79 endfunction
80
81 function foo2()
82   foo1()
83   x, y, z // Declared
84 endfunction
85
86 foo2()
87 // x y z does not exist here
88 ]]></programlisting>
89     </refsection>
90     <refsection role="see also">
91         <title>See Also</title>
92         <simplelist type="inline">
93             <member>
94                 <link linkend="abort">abort</link>
95             </member>
96             <member>
97                 <link linkend="break">break</link>
98             </member>
99             <member>
100                 <link linkend="pause">pause</link>
101             </member>
102             <member>
103                 <link linkend="quit">quit</link>
104             </member>
105             <member>
106                 <link linkend="return">return</link>
107             </member>
108             <member>
109                 <link linkend="execstr">execstr</link>
110             </member>
111         </simplelist>
112     </refsection>
113 </refentry>