SWITCH

From ASCEND
Revision as of 04:50, 2 April 2014 by Jpye (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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;