SWITCH: Difference between revisions

From ASCEND
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 4: Line 4:


See also [[IF]], [[SELECT]].
See also [[IF]], [[SELECT]].
Example (from {{src|models/ben/benHGthermo.a4l}}):
<source lang=a4c>
METHOD specify;
    (* other statements here... *)
    SWITCH (options.mixture_thermo_correlation)
    CASE 'UNIFAC':
        FREE partial[ds.components].V;
        FREE partial[ds.components].H;
        FREE partial[ds.components].G;
    CASE 'Wilson':
        FREE partial[ds.components].V;
        FREE partial[ds.components].H;
        FREE partial[ds.components].G;
    END SWITCH;
END specify;
</source>


[[Category:Syntax]]
[[Category:Syntax]]

Latest revision as of 04:50, 2 April 2014

The SWITCH statement, used within METHOD code, is essentially roughly equivalent to the C switch statement, except that ASCEND allows wildcard matches, allows any number of controlling variables to be given in a list, and assumes a break at the end of each CASE.

The SWITCH statement does not provide for conditional modelling, because the 'decision' code is only run during METHOD execution, not during solution of the model. The equivalent conditional modelling statement in ASCEND is WHEN.

See also IF, SELECT.

Example (from models/ben/benHGthermo.a4l):

METHOD specify;
    (* other statements here... *)
    SWITCH (options.mixture_thermo_correlation)
    CASE 'UNIFAC':
        FREE partial[ds.components].V;
        FREE partial[ds.components].H;
        FREE partial[ds.components].G;
    CASE 'Wilson':
        FREE partial[ds.components].V;
        FREE partial[ds.components].H;
        FREE partial[ds.components].G;
    END SWITCH;
END specify;