You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Defines a single line function with the function name `name` and the parameters `par1` to `parN`. `expression` is a valid SmallBASIC expression returning a value.
6
6
7
7
See FUNC for multiline functions and SUB for multiline subroutines.
8
8
9
-
Example 1: Function with one parameter
9
+
### Example 1: Function with one parameter
10
10
11
-
~~~
11
+
```
12
12
def f(x) = 2*x+3
13
-
14
13
print f(3)
15
-
~~~
14
+
```
16
15
17
-
Example 2: Function with two parameters
16
+
### Example 2: Function with two parameters
18
17
19
-
~~~
18
+
```
20
19
def f(x,y) = 2*x + 3*sin(y)
21
-
22
20
print f(1,2)
23
-
~~~
21
+
```
24
22
25
-
Example 3: Random number between low and high
23
+
### Example 3: Random number between low and high
26
24
27
-
~~~
25
+
```
28
26
' A function for random integer numbers between low and high (inclusive)
29
27
DEF randi(lo, hi) = (RND * (hi - lo + 1))\1 + lo
30
28
@@ -33,12 +31,11 @@ DEF randf(lo, hi) = (RND * (hi - lo + 1)) + lo
33
31
34
32
print randi(0, 100)
35
33
print randf(0, 100)
36
-
~~~
34
+
```
37
35
38
-
Example 4: DEF and LOCAL
39
-
40
-
~~~
36
+
### Example 4: DEF and LOCAL
41
37
38
+
```
42
39
' DEF and LOCAL.bas SmallBASIC 0.12.2 [B+=MGA] 2016-04-06
43
40
'can I use DEF locally in a sub without interfering with main variable or DEF names
0 commit comments