Fungsi pada BASIC (DEF)

Pendefinisian Fungsi / Def :

DEF FNNamaFungsi(Daftar Parameter)
Blok Pernyataan
END DEF

Pendeklarasian Variabel dalam Fungsi secara Local, Statis, Global:

Contoh Variabel Global:

rem program utama
csl
st$=”turbo basic”
print FNKapital$(st$)
print st$
END

rem program fungsi
DEF FNKapital$(x$)
st$=left$(x$,1)
FNKapital$=UCASE$(st$)
END DEF

rem hasil
rem T
rem t

Contoh Variabel Local:

rem program utama
csl
st$=”turbo basic”
print FNKapital$(st$)
print st$
END

rem program fungsi
DEF FNKapital$(x$)
Local st$
st$=left$(x$,1)
FNKapital$=UCASE$(st$)
END DEF

rem hasil
rem T
rem turbo basic

Contoh Variabel Statis: variabel yang hanya dikenal dalam blok tempat dideklerasikan dan tidak dikenal di luar blok, namun nilainya tidak hilang sekeluarnya dari fungsi.

rem program utama
csl
print FNStatis, N
print FNStatis, N
print FNStatis, M
END

rem program fungsi
DEF FNStatis
Static N
INCR N
FnStatis=N
END DEF

rem hasil
rem 1   0
rem 2   0
rem 3   0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s