mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-31 16:51:08 +00:00
Finished up the section on flow control and outlined the section on
functions. Added example script output to figures.
This commit is contained in:
parent
d85639d65e
commit
e338dd4672
5 changed files with 357 additions and 5 deletions
335
doc/gib/GIB.lyx
335
doc/gib/GIB.lyx
|
@ -1389,7 +1389,15 @@ ifnot
|
||||||
is as follows:
|
is as follows:
|
||||||
\layout LyX-Code
|
\layout LyX-Code
|
||||||
|
|
||||||
if condition block1 [else block2]
|
|
||||||
|
\family sans
|
||||||
|
if
|
||||||
|
\family default
|
||||||
|
condition block1 [
|
||||||
|
\family sans
|
||||||
|
else
|
||||||
|
\family default
|
||||||
|
block2]
|
||||||
\layout Standard
|
\layout Standard
|
||||||
|
|
||||||
Explanations of what each part means follow:
|
Explanations of what each part means follow:
|
||||||
|
@ -1476,7 +1484,7 @@ if
|
||||||
|
|
||||||
\begin_inset Float figure
|
\begin_inset Float figure
|
||||||
wide false
|
wide false
|
||||||
collapsed true
|
collapsed false
|
||||||
|
|
||||||
\layout LyX-Code
|
\layout LyX-Code
|
||||||
\line_top \line_bottom
|
\line_top \line_bottom
|
||||||
|
@ -1487,6 +1495,20 @@ preview false
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{if-simple.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\layout Caption
|
\layout Caption
|
||||||
|
|
||||||
Simple
|
Simple
|
||||||
|
@ -1525,7 +1547,7 @@ else
|
||||||
|
|
||||||
\begin_inset Float figure
|
\begin_inset Float figure
|
||||||
wide false
|
wide false
|
||||||
collapsed true
|
collapsed false
|
||||||
|
|
||||||
\layout LyX-Code
|
\layout LyX-Code
|
||||||
\line_top \line_bottom
|
\line_top \line_bottom
|
||||||
|
@ -1536,6 +1558,20 @@ preview false
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{if-else.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\layout Caption
|
\layout Caption
|
||||||
|
|
||||||
|
|
||||||
|
@ -1590,6 +1626,20 @@ preview false
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{if-chain.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\layout Caption
|
\layout Caption
|
||||||
|
|
||||||
Chained
|
Chained
|
||||||
|
@ -1650,7 +1700,11 @@ true.
|
||||||
The formal syntax is:
|
The formal syntax is:
|
||||||
\layout LyX-Code
|
\layout LyX-Code
|
||||||
|
|
||||||
while condition block
|
|
||||||
|
\family sans
|
||||||
|
while
|
||||||
|
\family default
|
||||||
|
condition block
|
||||||
\layout Description
|
\layout Description
|
||||||
|
|
||||||
condition is the same as
|
condition is the same as
|
||||||
|
@ -1710,7 +1764,7 @@ while
|
||||||
|
|
||||||
\begin_inset Float figure
|
\begin_inset Float figure
|
||||||
wide false
|
wide false
|
||||||
collapsed false
|
collapsed true
|
||||||
|
|
||||||
\layout LyX-Code
|
\layout LyX-Code
|
||||||
\line_top \line_bottom
|
\line_top \line_bottom
|
||||||
|
@ -1750,4 +1804,275 @@ while
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Subsubsection
|
||||||
|
|
||||||
|
|
||||||
|
\family typewriter
|
||||||
|
for
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
The for loop executes a program block once for every argument in a list.
|
||||||
|
Each execution, a variable will be set to the value of the current argument.
|
||||||
|
Syntax:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\family sans
|
||||||
|
for
|
||||||
|
\family default
|
||||||
|
variable
|
||||||
|
\family sans
|
||||||
|
in
|
||||||
|
\family default
|
||||||
|
list block
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
variable is the variable that will be set to the value of the current argument
|
||||||
|
each time the program block is executed.
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
in is a simple placeholder between
|
||||||
|
\family typewriter
|
||||||
|
variable
|
||||||
|
\family default
|
||||||
|
and
|
||||||
|
\family typewriter
|
||||||
|
list
|
||||||
|
\family default
|
||||||
|
.
|
||||||
|
It emphasizes the fact that
|
||||||
|
\emph on
|
||||||
|
for
|
||||||
|
\emph default
|
||||||
|
each argument
|
||||||
|
\emph on
|
||||||
|
in
|
||||||
|
\emph default
|
||||||
|
the list, the program block will be executed.
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
list can be any number of arguments, including expansions.
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
block must be the last argument to
|
||||||
|
\family typewriter
|
||||||
|
for
|
||||||
|
\family default
|
||||||
|
, and it must be a program block.
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
Figure
|
||||||
|
\begin_inset LatexCommand \vref{cap:for}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
shows an example
|
||||||
|
\family typewriter
|
||||||
|
for
|
||||||
|
\family default
|
||||||
|
loop and its output.
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Float figure
|
||||||
|
wide false
|
||||||
|
collapsed false
|
||||||
|
|
||||||
|
\layout LyX-Code
|
||||||
|
\line_top \line_bottom
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{for.gib}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{for.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Caption
|
||||||
|
|
||||||
|
Example
|
||||||
|
\family typewriter
|
||||||
|
for
|
||||||
|
\family default
|
||||||
|
loop
|
||||||
|
\begin_inset LatexCommand \label{cap:for}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Subsubsection
|
||||||
|
|
||||||
|
Additional Loop Functions:
|
||||||
|
\family typewriter
|
||||||
|
break
|
||||||
|
\family default
|
||||||
|
and
|
||||||
|
\family typewriter
|
||||||
|
continue
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
Two functions are available to control the behavior of loops during execution
|
||||||
|
of their program blocks:
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
break immediately ends the program block and leaves the loop.
|
||||||
|
\layout Description
|
||||||
|
|
||||||
|
continue returns to the top of the loop.
|
||||||
|
This means that
|
||||||
|
\family typewriter
|
||||||
|
while
|
||||||
|
\family default
|
||||||
|
loops check their condition argument again and
|
||||||
|
\family typewriter
|
||||||
|
for
|
||||||
|
\family default
|
||||||
|
loops move to the next argument in the list.
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
Figure
|
||||||
|
\begin_inset LatexCommand \vref{cap:break}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
shows an example use of
|
||||||
|
\family typewriter
|
||||||
|
break
|
||||||
|
\family default
|
||||||
|
and its output, while Figure
|
||||||
|
\begin_inset LatexCommand \vref{cap:continue}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
shows an example use of
|
||||||
|
\family typewriter
|
||||||
|
continue
|
||||||
|
\family default
|
||||||
|
.
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Float figure
|
||||||
|
wide false
|
||||||
|
collapsed false
|
||||||
|
|
||||||
|
\layout LyX-Code
|
||||||
|
\line_top \line_bottom
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{break.gib}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{break.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Caption
|
||||||
|
|
||||||
|
Example use of
|
||||||
|
\family typewriter
|
||||||
|
break
|
||||||
|
\begin_inset LatexCommand \label{cap:break}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Float figure
|
||||||
|
wide false
|
||||||
|
collapsed false
|
||||||
|
|
||||||
|
\layout LyX-Code
|
||||||
|
\line_top \line_bottom
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{continue.gib}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Standard
|
||||||
|
|
||||||
|
|
||||||
|
\series bold
|
||||||
|
Output:
|
||||||
|
\layout LyX-Code
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Include \verbatiminput{continue.gib.out}
|
||||||
|
preview false
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Caption
|
||||||
|
|
||||||
|
Example use of
|
||||||
|
\family typewriter
|
||||||
|
continue
|
||||||
|
\begin_inset LatexCommand \label{cap:continue}
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\layout Section
|
||||||
|
\pagebreak_top
|
||||||
|
Functions
|
||||||
|
\layout Subsection
|
||||||
|
|
||||||
|
Types and Concepts
|
||||||
|
\layout Subsection
|
||||||
|
|
||||||
|
Defining Functions
|
||||||
|
\layout Subsection
|
||||||
|
|
||||||
|
Accessing Arguments
|
||||||
|
\layout Subsection
|
||||||
|
|
||||||
|
Return Values
|
||||||
|
\layout Subsubsection
|
||||||
|
|
||||||
|
Returning Values from Functions
|
||||||
|
\layout Subsubsection
|
||||||
|
|
||||||
|
Embedding Return Values
|
||||||
|
\layout Subsubsection
|
||||||
|
|
||||||
|
Expanding Return Values
|
||||||
\the_end
|
\the_end
|
||||||
|
|
8
doc/gib/break.gib
Normal file
8
doc/gib/break.gib
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
num = 4
|
||||||
|
while $num {
|
||||||
|
echo Number: $num
|
||||||
|
if ($num == 2) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
num = ($num - 1)
|
||||||
|
}
|
6
doc/gib/continue.gib
Normal file
6
doc/gib/continue.gib
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
for num in 1 2 3 4 {
|
||||||
|
if ($num == 3) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
echo Number: $num
|
||||||
|
}
|
10
doc/gib/examples.sh
Executable file
10
doc/gib/examples.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# This script is in the public f'ing domain.
|
||||||
|
# You can burn it to a CD and use it as a
|
||||||
|
# frisbee for all I care.
|
||||||
|
|
||||||
|
for example in *.gib; do \
|
||||||
|
carne "$example" >"${example}.out"; \
|
||||||
|
done
|
||||||
|
|
3
doc/gib/for.gib
Normal file
3
doc/gib/for.gib
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
for num in 1 2 3 4 {
|
||||||
|
echo Number: $num
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue