http://alpha-thema-online.uv.ro
Fa-ti si tu propriul forum, pe www.myforum.ro!
Pagina de start a forumului http://alpha-thema-online.uv.ro Autentificare Inregistrare FAQ Membri Cautare

Pagina de start a forumului http://alpha-thema-online.uv.ro » Exemple Coduri » The Ins and Outs of Functions
Creaza un subiect nou  Raspunde la subiect Subiectul anterior :: Subiectul urmator 
The Ins and Outs of Functions
MesajTrimis: 06/07/2007 09:42 Raspunde cu citat (quote)
Ad_Infinitum
Administrator
Administrator
Ad_Infinitum
Data inscrierii: 23/Iun/2007
Mesaje: 212




remstart
Functions Example 3
In the first example, our value remained static, no matter how many times we incremented it.
By passing in the value as a paremeter, and receiving it back again afterwards,
the value can be retained. In a real programming situation, you might use this
feature of functions to calculate a new character position,
evaluate health based on numerous factors (or parameters), or simply perform a
long-winded calculation that is "tidier" in the form of a function.
remend

` Basic Setup
`******************************************************
set display mode 640,480,16
sync on: sync rate 10


` Main routine
`******************************************************
` Call the function Counter() 1000 times
for looping = 1 to 1000
cls
MainValue = Counter(MainValue)
center text 320, 200, "Main Code : I have looped " + str$(looping) + " times"
center text 320, 420, "Press 'Esc' to Exit"
if escapekey() then end
sync
next looping


` End Program
`******************************************************
end




`******************************************************
` Functions
` Functions always appear after the main body of your code.
` Although there is an "end" statement above for completeness,
` it is not essential. Your functions will NOT run, until
` you call them explicitly. This is the first major difference
` between Subs and Functions.
`******************************************************


function Counter(MyValue)

` Increment the value of n, and display
inc MyValue, 1
center text 320, 240, "Function : I have incremented MyValue, it's value is now " + str$(MyValue)

endfunction Myvalue



---------------------------------ScreenShot----------------------------------


The Ins and Outs of Functions The Ins and Outs of Functions
Vezi profilul utilizatorului Trimite mesaj privat

The Ins and Outs of Functions
 Pagina de start a forumului http://alpha-thema-online.uv.ro » Exemple Coduri
Nu puteti crea un subiect nou in acest forum
Nu puteti raspunde in subiectele acestui forum
Nu puteti modifica mesajele proprii din acest forum
Nu puteti sterge mesajele proprii din acest forum
Nu puteti vota in chestionarele din acest forum
Ora este GMT + 3 ore  
Pagina 1 din 1  

  
  
 Creaza un subiect nou  Raspunde la subiect  


Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
    Powered by phpBB © 2001-2004 phpBB Group. phpBB Skin by Vjacheslav Trushkin.