Options

How does EXIT function works

liizzliizz Member Posts: 125
How is the EXIT function used when there need be to return variable?

For e.g:

IF statement1 THEN
EXIT(FALSE);
ELSE
statement2;
EXIT(TRUE);

What does the EXIT(FALSE) and EXIT(TRUE) mean?

Please advise.

Thanks
Liizz

Comments

  • Options
    DenSterDenSter Member Posts: 8,304
    From the Classic Client, click on the Help menu and select 'C/SIDE Reference Guide'. In the Search tab, enter 'EXIT' and click the "list topics" button. There's a whole list of topics that you can read that explains the various C/AL commands, and EXIT is in there somewhere.
  • Options
    liizzliizz Member Posts: 125
    I have already checked the EXIT function on Help.

    Its a function that will exit either a true or a false variable.

    But how to know when it should exit with TRUE or FALSE values.

    This is my question.

    This is a standard code on Classic:

    IF ApprovalTemplate.FIND('-') THEN
    EXIT(TRUE)
    ELSE
    EXIT(FALSE);

    Lets say if the boolean return variable has been interchanged.

    Thanks to clarify me.

    Liizz
  • Options
    mohana_cse06mohana_cse06 Member Posts: 5,503
    The function is checking whether there is any Approval templte exists or not..

    If record found then it is returning boolean TRUE
    if not found FALSE

    based on the return value from function the process may be different..
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    liizz wrote:
    This is a standard code on Classic:

    IF ApprovalTemplate.FIND('-') THEN
    EXIT(TRUE)
    ELSE
    EXIT(FALSE);


    If it was written
    EXIT(ApprovalTemplate.FIND('-'));
    

    it would make more sense to read.
    David Singleton
  • Options
    DenSterDenSter Member Posts: 8,304
    liizz wrote:
    I have already checked the EXIT function on Help.

    Its a function that will exit either a true or a false variable.
    Doesn't look like you really read it to me.

    EXIT is the command that you use to jump out of a function, and between the parentheses you define the value of the return value. In this particular case, the return value is a boolean, so it is TRUE or FALSE. You can define any data type in the return value, and EXIT with any value that belongs to that data type. If you don't define a return value, you simply say EXIT without a parameter.

    So if your return value is a text data type, you can say EXIT('Bye Bye'), if it is a decimal you can say EXIT(3.14), etcetera.

    Read the C/SIDE Reference Guide again. Open up some big codeunits and search for the EXIT command and see how it's used in the standard code. By doing this, you might actually learn something.
  • Options
    colingbradleycolingbradley Member Posts: 162
    Strange to say but EXIT is not listed in the online Help (NAV2009 SP1) and it has nothing in the Search option except a lot of entries with exit (in lowercase).
    Thanks to Denster, we have a detailed explanation.
    Experience is what you get when you hoped to get money
  • Options
    gerrykistlergerrykistler Member Posts: 149
    You must be in the code of an object when you go to help.
    Here it is:
    EXIT Statement
    The EXIT statement is used to control the flow of the execution. The following syntax shows an EXIT statement.

    Copy Code
    EXIT([<Value>])


    An EXIT statement is used to interrupt the execution of a C/AL trigger. The interruption takes place even when the code is executed inside a loop or a similar structure. The EXIT statement is also used when a local function should return a value.

    Using EXIT without a parameter in a local function corresponds to using the parameter value 0. The C/AL function will return the value 0 or '' (empty string).

    A compile-time error occurs if EXIT is called with a return parameter from either of the following:

    System-defined triggers

    Local functions that do not return a value

    Example
    The following example shows the use of the EXIT statement in a local function. Assume that the IF statement is used to detect an error. If the error condition is met, then execution is stopped and the local function returns the error code 1.

    Copy Code
    FOR I := 1 TO 1000 DO BEGIN
    IF Amount < Total THEN
    EXIT(1);
    A := Amount + Total;
    END;

    Gerry Kistler
    KCP Consultores
  • Options
    colingbradleycolingbradley Member Posts: 162
    I Found it in the Search using the filter EXIT(FALSE) / C/AL Repetitive Statements.

    After scrolling down through to the end, I found the same text as you describe.

    The FOR WHILE REPEAT help is in the first section of help text, so it is not that obvious.
    Experience is what you get when you hoped to get money
  • Options
    DenSterDenSter Member Posts: 8,304
    EXIT is not listed in the online Help (NAV2009 SP1) and it has nothing in the Search option except a lot of entries with exit (in lowercase).
    That's why I mentioned the C/SIDE Reference Guide, not F1 help or online help. From the Classic Client, click the Help menu and select 'C/SIDE Reference Guide'. You're right, if you enter 'EXIT' in the search, there's not a separate entry for EXIT, but just clicking down the list and reading through the stuff that DOES come up, you will get to it eventually.

    I never said it was easy to find :mrgreen: but the C/SIDE Reference Guide is a gem that surprisingly many people never use.
  • Options
    SavatageSavatage Member Posts: 7,142
    I Found it in the Search using the filter EXIT(FALSE) / C/AL Repetitive Statements.
    http://msdn.microsoft.com/en-us/library/dd355086.aspx
Sign In or Register to comment.