If Statement 

If Statement SyntaxAn if statement is used to control program execution in a Fractal Science Kit fractal program. An if statement has several different forms. Each form evaluates 1 or more conditional expressions and determines what statements should be executed based on the results. Syntax 1: if (<Condition>) { This form evaluates the conditional expression and executes the statements within the if block if and only if the expression is true. Syntax 2: if (<Condition>) { This form evaluates the conditional expression and executes the 1^{st} block of statements if the expression is true or the 2^{nd} block of statements if the expression is false. Syntax 3: if (<Condition>) { This form evaluates a conditional expression and executes the 1^{st} block of statements if the expression is true. Otherwise, the 2^{nd} conditional expression is evaluated and if true, the 2^{nd} block of statements is executed. If both conditional expressions are false, the 3^{rd} block of statements is executed. This form can include any number of elseif blocks and the final else block is optional. Example 1: if (Abs(z) > 1) { This statement executes the return statement if Abs(z)>1. Example 2: if (x = 0) { This statement sets r to different values based on the value of x. The above statement could also have been written in the abbreviated form: r = IIf(x = 0, 1, Sin(x)/x) This uses the special function IIf to evaluate the conditional expression and return 1 of the 2 expressions based on the result. IIf Syntax: IIf(<Condition>, <ValueIfTrue>, <ValueIfFalse>) Only 1 of the expressions <ValueIfTrue> or <ValueIfFalse> is evaluated, depending on the conditional expression. This is contrasted with normal function invocation, which evaluates all of the function arguments before calling the function. Example 3: if (t < 0) { This statement ensures that t is between 0 and 1 inclusive as does the following: t = IIf(t < 0, 0, IIf(t > 1, 1, t)) 
Copyright © 20042016 Hilbert, LLC 