
-----------------------------------
Cervantes
Sat Feb 21, 2004 10:41 am

[Help] [Blitz] Functions
-----------------------------------
In Turing a function is like a procedure that has a result correct? (I never did funcs in class, and not much outside of class)

Functions in Blitz seem to be a bit different to me, though I'm really not too sure :?  Anyways, could you write a quick tutorial on funcs in Blitz shorthair? 
Much oblidged :)

-----------------------------------
shorthair
Sat Feb 21, 2004 10:58 am


-----------------------------------
Blitz Help    ( if you dont get it , il write my own for you )

Function {funcname}{typetag}( {params} ) 
     {statements} 
End Function 

{funcname}
 is any valid identifier. 

{typetag} 
is the type of value returned by the function. If {typetag} is omitted, the function returns an integer value by default. 

{params} 
is a comma separated list of variables which is passed to the function when it is called, each parameter may be given an optional type tag. Parameters are always local. 

A function may use the 'Return' statement to return a result. Just like turing , functions are very useful,

If there is no Return statement, or a Return without any expression is used, the function returns a default value of 0 for numeric functions, an empty string ("") for string functions, or a 'Null' object for custom type functions. 
[/b]

-----------------------------------
Cervantes
Sat Feb 21, 2004 11:58 am


-----------------------------------
K I'm kinda understanding these now. 


Function larger (number1, number2)
If number1 > number2 Then
 output = number1 + " is the largest number."
ElseIf number1 = number2 Then
 output = number1 + " is equal to " + number2
Else
 output = number2 + " is the largest number."
EndIf
End Function

Global num1, num2 
Global output$
num1 = Input ("Enter first number  ")
num2 = Input ("Enter second number ")
larger (num1, num2)
Print output


Do you have to have the function return something?  
Is gosub the closest thing to procedure?

-----------------------------------
shorthair
Sat Feb 21, 2004 12:13 pm


-----------------------------------
if you dont need hte funtion to return somthing , then you shouldnt be using a function  , you know like turing has procedures and functions , they both have their uses
