if() – Conditional Flow Control

The if() command allows the script to direct “execution” of various parts of the script based on the condition.

It is really very basic, if your condition is True the contents of the if() command will be included in the model.

What get’s included ( scope )

The scope of the if() command is the same a s any other model. The scope is either the first child or the bracketed contents.

Child() scope

if( condition )
     child;

also

if( condition )
     modifier() transform() primitive([]);

Basically the child is the first additive including any modifiers, A single child basically is created at the end of a series of command, ending with a semi-colon;

Bracketed Scope

If you would like to apply the conditional execution to more than one child object at a time simply include them in brackets after the if() command.

if( condition ) {
     childone();
     childtwo();
     modifier() childthree();
     difference(){ childa(); childb; )
}

Else

For basic test you can include content in the model or exclude it by using an Else and eliminate the need for a second test.

The scope works the same as the if() portion

if( condition ) 
     childone();
else
     childtwo();

In the above example childone() will be rendered if the condition evaluates as true. If the condition evaluates as false childtwo() will be included.

Conditional Operators

All lthe standard operators are available

  • < > Less Than or Greater Than ( one at a time )
  • == Is equal to
  • != is not equal to
  • && Both conditions are True
  • ! The condition is not True
  • true The value of 1, an expression that evaluates to 1, keyword true
  • False The value of 0, an expression that evaluates to 0, keyword false

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: