File: return.mdc

package info (click to toggle)
freemat 4.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 141,800 kB
  • ctags: 14,082
  • sloc: ansic: 126,788; cpp: 62,046; python: 2,080; perl: 1,255; sh: 1,146; yacc: 1,019; lex: 239; makefile: 100
file content (96 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

 Usage

The return statement is used to immediately return from a
function, or to return from a keyboard session. The syntax
for its use is

    return

Inside a function, a return statement causes FreeMat to exit
the function immediately. When a keyboard session is active,
the return statement causes execution to resume where the
keyboard session started.


 Example

In the first example, we define a function that uses a
return to exit the function if a certain test condition is
satisfied.

       return_func.m


  function ret = return_func(a,b)
    ret = 'a is greater';
    if (a > b)
      return;
    end
    ret = 'b is greater';
    printf('finishing up...\n');

Next we exercise the function with a few simple test cases:

  --> return_func(1,3)
  finishing up...

  ans =
  b is greater
  --> return_func(5,2)

  ans =
  a is greater

In the second example, we take the function and rewrite it
to use a keyboard statement inside the if statement.

       return_func2.m


  function ret = return_func2(a,b)
    if (a > b)
       ret = 'a is greater';
       keyboard;
    else
       ret = 'b is greater';
    end
    printf('finishing up...\n');

Now, we call the function with a larger first argument,
which triggers the keyboard session. After verifying a few
values inside the keyboard session, we issue a return
statement to resume execution.

  --> return_func2(2,4)
  finishing up...

  ans =
  b is greater
  --> return_func2(5,1)
  [return_func2,4]--> ret

  ans =
  a is greater
  [return_func2,4]--> a

  ans =
   5

  [return_func2,4]--> b

  ans =
   1

  [return_func2,4]--> return
  finishing up...

  ans =
  a is greater


* FreeMat_Documentation
* Flow_Control
* Generated on Thu Jul 25 2013 17:17:14 for FreeMat by
  doxygen_ 1.8.1.1