exit from function

Hi all,
My kshell code is not working, when I use a function to return something. But when I use the same function as without returning any values, it is working. Pls help me here.

Code1 :

func1 () {
         y=`echo $x | grep XXX| cut -f 2 -d ' '`
         if [ -z "$y" ]; then
         exit 100
         else
         echo $y
         fi
}
x="HAPPY WORLD"
z=`func1`
echo $x
echo $z

Output:

HAPPY WORLD

Code2:

x="HAPPY WORLD"
func1 #same function as above#
echo $x

No output.... exit command into the function worked here.

How can I change my fucntion in code1 to exit from the script?

Regards,
Poova.

exit: exits from the script.
to get out of a function, use return

Return exit the function, exit exit the script. Both set exit code to the variable ?.

#!/bin/ksh or bash or dash or sh or ....
func1 () {
  arg="$*"
  case "$arg" in
        *XXX*)   flds=($arg)
                 y="${flds[1]}"
                 [ "$y" = "" ] && return 100
                 echo "$y"
                 return 0
                 ;;
   esac
   return 1
}

###########################################

for x in "HAPPY WORLD"  "1XXX1 some" "2XXX"  "123 XXX"
do
        z=$(func1 "$x")
        stat=$?
        echo "_____________________"
        for var in x z stat
        do
           eval echo $var: \$$var
        done
done