Excerpt from C#

Statements in C# must always end with a semicolon.

Example

int i = 5;

Variables

New variables must be declared in the formula. The declaration is made by entering the type name followed by the name of the variable and then a semicolon at the end of the statement.

The variable can also be initialized using "=".

The name of the variable may consist of letters and numbers. It must start with a letter and cannot contain any special characters, with the exception of an underscore "_".

Assignments to variables are also implemented using "=".

Example

string s1 = "Hello";

string s2 = "world";

s1 = s2;

Note

Make sure not to declare variables twice.

The input and output parameters of the formulas are already declared internally. They do not need to be declared separately.

Types

C# has different value types. For the sake of simplicity, only the following types should be used when programming formulas for the Technology mode:

  • double
  • int
  • bool
  • string
Note

When assigning a value of "string" type to a variable, the value must be enclosed in quotation marks.

Example

string s = "Hello;

Comments

Comments are used to add remarks or for debugging.

For debugging purposes, two separate areas are commented out:

Comments are entered either with "//" for each line, or with "/*" and "*/" per block.

Example

/*

Comment

*/

Statements

If-statement

To evaluate comparisons, it is best to use an if-statement.

It consists of one or more of the keywords "if", "else" or "else if", the expression to be tested (comparison or logical expression) in parentheses, and the statement block delimited using braces.

You can find a selection of comparison operators in Comparison Operators.

Example

if (i == 0)

{

a = 5;

}

else if (i > 0)

{

a  = 10;

}

else

{

a = 0;

}

Switch-statement

A simple way to evaluate an equality is to use the switch-statement.

It consists of the keyword "switch", followed by the variable to be evaluated in parentheses plus one or more case lines that are delimited using braces.

A "case" line consists of the keyword "case", followed by the value to match a variable, a colon and the statement block, which must end with the keyword "break;".

A "case" line may also flow on directly to another line (without "break;"), in which case the statement block applies to both values.

The default keyword is used to determine what will be executed if neither of the two values is true.

Example

switch (a)

{

case 1:

case 2:

b = 5;

break;

case 3:

b  = 10;

break;

case 4:

b = 20;

break;

default:

b = 0;

break;

}

While-statement

The while-statement allows a pre-test loop to be implemented.

The statement block is repeated for as long as the expression being tested is true, and it must be true for the first test.

The while-statement consists of the keyword "while", followed by the expression to be tested (comparison of logical expression) in parentheses, and the statement block in braces.

You can find a selection of comparison operators in Comparison Operators.

Note

Note that a so-called endless loop (where the expression to be tested is always true) is not tested in the current version of FACTON This may cause the software to crash, risking a loss of data.

Example

int a = 0;

while (a < 5)

{

a = a + 1;

}

For loop

The for-statement can be used to implement a counting loop.

It consists of the keyword "for", followed by three statement blocks enclosed in parentheses that initialize the counting loop.

The first of the three statement blocks initializes the counter variable.

The second contains the expression to be evaluated (comparison or logical expression). The loop will be executed as long as the expression is true.

The third statement block either increments or decrements the counter variable.

The actual statement block follows inside braces.

You can find a selection of comparison operators in Comparison Operators.

Note

Note that a so-called endless loop (where the expression to be tested is always true) is not tested in the current version of FACTON This may cause the software to crash, risking a loss of data.

Example

int a = 5;

for (int i = 0; i < a; i++)

{

b = b + 1;

}

Mathematical functions

The following is a selection of mathematical functions:

Math.E Represents the base of the natural logarithm by the constant e.
Math.PI > Is the ratio of the circumference of a circle divided by the diameter of the circle represented by the constant Pi.
Math.Abs(x) Returns the absolute value of a given number x.
Math.Acos(x) Returns an angle whose cosine equals the given number x.
Math.Asin(x) Returns an angle whose sine equals the given number x.
Math.Atan(x) Returns an angle whose tangent equals the given number x.
Math.Atan2(x,y) Returns an angle whose tangent equals the quotient of two given numbers x and y.
Math.Ceiling(x) Returns the smallest integer that is greater than or equal to the given number x.
Math.Cos(x) Returns the cosine of the given angle x.
Math.Cosh(x) Returns the hyperbolic cosine of the given angle x.
Math.Exp(x) Returns the given power x of e.
Math.Floor(x) Returns the largest integer that is smaller than or equal to the given number x.
Math.IEEERemainder(x,y) Returns the remainder from the division of two given numbers x and y.
Math.Log(x) Returns the natural logarithm (to the base e) of a given number x.
Math.Log(x,b) > Returns the logarithm of a given number x in relation to the given base b.
Math.Log10(x) Returns the logarithm of a given number x to the base 10.
Math.Max(x,y) Returns the larger of two given numbers x and y.
Math.Min(x,y) Returns the smaller of two given numbers x and y.
Math.Pow(x,e) Raises a given number x to the given power of e.
Math.Round(x) Returns the nearest integer to the given value.
Math.Round(x,n) Returns the number with the given accuracy n that is closest to the given value x.
Math.Sign(x) Returns a value indicating the operational sign of the given number x.
Math.Sin(x) Returns the sine of the given angle x.
Math.Sinh(x) Returns the hyperbolic sine of the given angle x.
Math.Sqrt(x) Returns the square root of a given number x.
Math.Tan(x) Returns the tangent of the given angle x.
Math.Tanh(x) Returns the hyperbolic tangent of the given angle x.

Mathematical operators

The following is a selection of mathematical operators:

+ Addition: x + y
- Subtraction: x - y
* Multiplication: x * y
/ Division: x / y
% Modulo: x % y

Comparison Operators

The following is a selection of comparison operators:

x == y x equal to y
x != y x not equal to y
x > y x greater than y
x < y x less than y
x >= y x greater than or equal to y
x <= y x less than or equal to y