I would like to compare the result (0 or 1) of a function in a while loop. Function `validmask` checks whether the entered input is in mask format. If so I get `1`, and if not I get `0`.

I want to run the `mask=$(whiptail ...)` command and check the value of `$mask with the`validmask` function until it returns a valid mask. 

My problem is that I can't run the function again; my script exits after a single run. I know I have to put the function in the if statement, but I don't know how. Or is there better solution?

Here is the code:

```
if validmask $mask; then stat2='1'; else stat2='0'; fi
while validmask
do
   if [[ $stat2 == 0 ]]; then
        mask=$(whiptail --title "xx" --inputbox --nocancel "Bad entry" 3>&1 1>&2 2>&3)
   fi
done

```

**ADDED**
Function validmask

```
function validmask()
{
    local  mask=$1
    local  stat2=1

    if [[ $mask =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        mask=($mask)
        IFS=$OIFS
        [[ ${mask[0]} -le 255 && ${mask[1]} -le 255 \
            && ${mask[2]} -le 255 && ${mask[3]} -le 255 ]]
        stat2=$?
    fi
    return $stat2
}

```

Also in loop while should be check if mask is valid or not. I got **above** `if validmask $mask; then stat2='1'; else stat2='0'; fi` 
code what checks empty input.

```
while [[ -z "$mask" ]]
do
   mask=$(whiptail --title "xx" --inputbox --nocancel "Mask" 3>&1 1>&2 2>&3)
done

```

If I start my script I am able to fill in just one time a mask. A function validmask is not executed again.