Ciklusok
0 1 1 4 {add} for 10
szám eljárás repeat -
For:
kezd növekm vég proc for --
Kiveszi a négy objektumot a verembõl ( kezd, növekm, vég, számok ), egy ideiglenes belsõ változót hoz létre ( számláló ), aminek az értéke kezdetben kezd lesz.
Ha a számláló <= vég, akkor a számlálót elhelyezi a verembe, végrehajtja a proc-ot és növekménnyel inkrementálja a számlálót. ( ha a növekmény negatív, akkor a végfeltétel: számláló < vég )
pl.:
1 2 6 {} for 1 3 5
3 -.5 1 {} for 3.0 2.5 2.0 1.5 1.0
0 12 600 {moveto (k) show} for
/Times-Italic findfont 30 scalefont setfont
/printZip {
0 0 moveto
(Zip) show
} def%**** MAIN ****
newpath
320 400 translate
.95 -.05 0 {
0 0 setrgbcolor printZip
-1 0.5 translate
} for1 setgray
printZipshowpage
Loop:
proc loop --
Addig ismétli a proc végrehajtását, amíg exit operátort talál ( különben végtelen ciklus ).
- exit -
kiugrik a legbelsõ ciklusból ( amiben az exit van ).pl.:
/pagewidth 8.5 72 mul def
/doCircle {
xpos ypos radius 0 360 arc
stroke
} def/increase-x {
xpos radius add
/xpos exch def
} def/lineofcircles {
/ypos exch def
/radius exch def
/xpos 0 def
{xpos pagewidth le
{doCircle increase-x}
{exit}
ifelse
} loop
} def%**** MAIN ****
newpath
1 0 0 setrgbcolor
10 400 lineofcircles
0 1 0 setrgbcolor
30 400 lineofcircles
0 0 1 setrgbcolor
90 400 lineofcirclesshowpage
Rekurzió: Önmagát hívó eljárás
/str 20 string def
/LM 72 def
/Times - Roman findfont 15 scalefont setfont
/nstr 7 string def
/newline
{ currentpoint 16 sub
exch pop
LM exch
moveto }
/factorial
{ gup 1 gt
{ dup 1 sub factorial mil } if
} def
/prt-n
{nstr cvs show} def
/prtFactorial
{ dup prt-n
(!=) show
factorial prt-n
newline } def
%Program -----------
LM 600 moveto
1 1 10 {prtFactorial} for
showpage
int string szöveg
int hosszúságú szöveget hoz létre
x ' string ' cvs szöveg
x-et szöveggé konvertálja, string-be rakja és
pl.:
123 456 add str cvs (579)
Rekurzív grafika:
/depth 0 def
/maxdepth 10 def
/down{/depth depth 1 add def}def
/up{/depth depth 1 sub def}def/DoLine
{0 144 rlineto currentpoint stroke translate 0 0 moveto}def
/FractArrow
{gsave .7 .7 scale 10 setlinewidth down DoLine depth maxdepth le
{135 rotate FractArrow -270 rotate FractArrow} if up grestore}def300 400 moveto
FractArrow
stroke
showpage
a lap teteje