Main Content

Check description of conditional expressions

Check ID: mathworks.jmaab_v6.mp_0022

Guideline: mp_0022: How to describe conditional expressions

Description

Checks if conditional expressions adhere to the following guidelines.

  • while, if, and if-else expressions evaluate to a single logical value, true or false.

  • The number of binary operators in each line of a while, if, if-else, or switch expression does not exceed the maximum allowed value.

    This condition applies to binary operators.

  • If while, if, if-else, or switch expressions contain logical operators and have one or more line breaks in the middle of the expression, then one of the following conditions is met.

    • A line break in the middle of the expression occurs immediately after a logical operator.

    • A line break in the middle of the expression occurs immediately before a logical operator.

    This condition applies to logical operators: &, &&, |, and ||

This check applies to the following target components:

  • MATLAB Function blocks in Simulink®.

  • Embedded MATLAB® functions in Stateflow® charts.

  • States, transitions, and truth tables in Stateflow MATLAB charts.

  • External MATLAB files referenced in a model.

This check requires a Simulink Check™ license.

Check Parameterization

This check contains sub-checks that correspond to sub IDs specified in the JMAAB modeling guidelines. You can use the Model Advisor Configuration Editor to specify which sub IDs (one or multiple) to execute.

For reference, the guideline sub ID(s) that are recommended for use by the JMAAB modeling standards organizations are:

  • JMAAB — a, b, c1/c2

Select Check external .m files referenced in the model, to include files with a .m extension in the analysis. The check box is selected by default.

Enter a value in the Number of Binary Operators in a line box to specify the maximum number of binary operators allowed in each line of a conditional expression. The default value is 3.

Results and Recommended Actions

Guideline Sub IDConditionRecommended Action
mp_0022_a: Check value of conditional expressionOne or more while, if, or if-else expressions do not evaluate to a single logical value true or false.Rewrite while, if, and if-else expressions to evaluate to a single logical value, true or false.
mp_0022_b: Check number of binary operators in a lineThe number of binary operators in each line of one or more while, if, if-else, or switch expressions exceed the maximum allowed value.Limit the number of binary operators in each line of a while, if, if-else, or switch expression to the value specified by the Number of Binary Operators in a line input parameter.
mp_0022_c1: Check format of complex conditional expressions

One or more while, if, if-else, or switch expressions containing logical operators do not satisfy the following format.

Line breaks in the middle of the expression must occur immediately after logical operators.

Rewrite while, if, if-else, and switch expressions so that each line break in the middle of an expression occurs immediately after a logical operator.
mp_0022_c2: Check format of complex conditional expressions

One or more while, if, if-else, or switch expressions containing logical operators do not satisfy the following format.

Line breaks in the middle of the expression must occur immediately before logical operators.

Rewrite while, if, if-else, and switch expressions so that each line break in the middle of an expression occurs immediately before a logical operator.

Capabilities and Limitations

  • Does not analyze states and transitions in Stateflow charts.

  • Does not check if code after the first line of a conditional expression is indented. By default, MATLAB enables indentation and sets an indent size. To view the indent size, on the Home tab, in the Environment section, click Preferences, and navigate to MATLAB > Editor/Debugger > Tab. Here, check the value entered in the Indent size box.

  • Analyzes content of library-linked blocks. By default, the input parameter Follow links is set to on. Here,

  • Analyzes content in masked subsystems. By default, the input parameter Look under masks is set to graphical.

  • Does not run on library models.

  • Allows exclusion of blocks and charts.