SWITCH

From ASCEND
Jump to: navigation, 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;