Why does the VAIL “RETURN” statement not terminate my procedure?

Assume that you run the following procedure:

PROCEDURE testReturn()
var x = 0
if (x == 0){
    return "In the IF statement"
}
return "At the end of the procedure"

Your output will be: “At the end of the procedure”

From the VAIL Rule and Procedure Reference Guide you find the following definition of the RETURN statement:

RETURN
VAIL procedures return a value when their execution completes. By default, the return value is the value produced by the last VAIL statement to execute. In order to make return values more explicit the RETURN statement may be used to specify the returned value. However, the RETURN statement MUST be the last statement in the body of the procedure. The RETURN statement CANNOT be used to terminate execution of the procedure earlier in the procedure body.

In the example above, you might want to add an ELSE clause so that it looks like this:

PROCEDURE testReturnWithElse()
var x = 0
if (x == 0){
    return "In the IF statement"
} else
{
    return "At the end of the procedure"
}

When you run the above procedure the output will be “In the IF statement”.

 

 

Posted: June 5, 2020 at 4:47 pm
Replies: 0
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
© Vantiq 2024 All rights reserved  •  Vantiq Corporation’s Privacy Policy and Cookie Policy