![]() Set variables to a new value for a sub-tree. Multiple nested conditionals can become difficult to understand.įormatting them like multi-line indented "if/else" statements is clearer. from the start (or s'th element) to the i'th element - remember elements are zero basedįunction sumv(v, i, s = 0) = (i = s ? v : v + sumv(v, i-1, s)) Įcho("sum vec=", sumv(vec, 2, 1)) // calculates 20+30=50įormatting complex usage If the limit is hit, the function returns undef.Įxample // recursion - find the sum of the values in a vector (array) by calling itself Note: There is a built-in recursion limit to prevent an application crash. " it's possible to ensure the recursion is terminated. Some forms of tail-recursion elimination are supported. This works like the ?: operator from the family of C-like programming languages.Įxamples a=1 b=2 c= a=b ? 4 : 5 // 5Ī=1 b=2 c= a=b ? "a=b" : "a!=b" // "a!=b"Įcho( test ? TrueValue : FalseValue ) // falseĪ1 = test ? TrueValue : FalseValue // Values can be stored in variables, passed as function arguments, and returned as function results. ![]() FalseValue: the value to return when test is false.Ī value in OpenSCAD is either a Number (like 42), a Boolean (like true), a String (like "foo"), a Vector (like ), or the Undefined value (undef). See here for boolean and logical operators Do not confuse assignment '=' with equal '=' TrueValue: the value to return when test is true. See here for true or false state of values. Parameters test: Usually a boolean expression, but can be any value or variable. start - initial value increment or step - amount to increase the value, optional, default = 1 end - stop when next value would be past end examples: for (a =)echo(a) // 3 4 5įor (a =)Ī function that uses a test to determine which of 2 values to return. ![]() Note: For range, values are separated by colons rather than commas used in vectors. ![]() Modules perform actions, but do not return values. Well chosen names also help document your script. This allows grouping portions of script for easy reuse with different values. Parameters As a range (see section on range) Users can extend the language by defining their own functions and modules. Evaluate each value in a range or vector, applying it to the following Action.įor(variable = ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |