File: code-blocks.2gg

package info (click to toggle)
golf 601.4.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ansic: 20,020; sh: 1,171; makefile: 292
file content (49 lines) | stat: -rw-r--r-- 1,377 bytes parent folder | download
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
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
code-blocks \- Golf documentation (program-flow)
.SH DESCRIPTION

.LP
.B CODE BLOCKS
.LP

Use curly braces ("{" and "}") to open and close a code block. They create a separate scope for previously non-existing variables defined within them, which begins with "{" and ends with "}". Note that if a variable existed in an outer scope, it cannot be created in the inner scope.

Note that \fBif-true\fP, \fBrun-query\fP, \fBstart-loop\fP and \fBread-line\fP statements contain implicit code blocks, meaning the code between them and the accompanying end-statement is within implicit "{" and "}".

.SH EXAMPLES
The following code will first print out "outside" and then "inside" twice, illustrating the fact that variable "s1" is defined only in the outer scope once. Variable "s2" exists only in inner scope:

.RS 4
.EX

begin-handler /scope public
    @<<print-out s1>>
    set-string s1="outside"
    {
        set-string s2="inner variable"
        set-string s1="inside"
        @<<print-out s1>>
    }
    @<<print-out s1>>
end-handler

.EE
.RE

.SH SEE ALSO
 Program flow

\fBbreak-loop\fP  
\fBcall-handler\fP  
\fBcode-blocks\fP  
\fBcontinue-loop\fP  
\fBdo-once\fP  
\fBexit-handler\fP  
\fBif-defined\fP  
\fBif-true\fP  
\fBquit-process\fP  
\fBreturn-handler\fP  
\fBstart-loop\fP   
See all 
\fBdocumentation\fP