Skip to content Skip to navigation

Connexions

You are here: Home » Content » Programming with M-Files: Logical Expressions

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Recently Viewed

This feature requires Javascript to be enabled.

Programming with M-Files: Logical Expressions

Module by: Darryl Morrell

Summary: This is a brief tutorial on the logical expressions used in if statements and while loops in m-file scripting environments.

Logical Expressions

Logical expressions are used in if statements, switch case statements, and while loops to change the sequence of execution of commands in response to variable values. A logical expression is one that evaluates to either true or false. For example, v > 0 is a logical expression that will be true if the variable v is greater than zero and false otherwise.

Note:

In m-file scripts, logical values (true and false) are actually represented by numerical values. The numerical value of zero represents false, and any nonzero numerical value represents true.

Logical expression are typically formed using the following relational operators:

Relational Operators
Symbol Relation
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
~= Not equal to

Note:

== is not the same as =; they are treated very differently in m-file scripting environments. == compares two values, while = assigns a value to a variable.

Complex logical expressions can be created by combining simpler logical expressions using the following logical operators:

Logical Operators
Symbol Relation
~ Not
&& And
|| Or

Comments, questions, feedback, criticisms?

Send feedback