Code:
Break On ; avoid system restart
$a=0
:A
$a=$a+1
if $a<5
  goto A
EndIF ; loop 5 times

$b=Fun1(1) ; get it
Messagebox("a = $a, b = $b","Test")
Exit ; show a and b

Function Fun1($a) ; 
  :B
  $a=$a+1
  if $a<6
     goto B
  EndIf ; loop 6 times
  $F1=$a
EndFunction ; return a value

Yeah Goto doesn't work within functions.
But it should not be used anyway, try to use loops instead:
 Code:
Break On ; avoid system restart
$a=0
while $a<5
  $a=$a+1
Loop ; loop 5 times

$b=Fun1(1) ; get it
Messagebox("a = $a, b = $b","Test")
Exit 0; show a and b

Function Fun1($a) ; 
  While $a<6
    $a=$a+1
  Loop ; loop 6 times
  $Fun1=$a
EndFunction ; return a value