# Delphi Programming/Flow control
## Structures
### The if-structure

The if-structure executes a block of commands if a boolean expression returns True. A more simple to understand explanation is: It executes a block or a single command if a condition is true. Example:
Never write "if a = True" but simply write "if a". Writing "if a = False" is correct, but you can also write "if not a" or (with brackets) "if (((((a)))))" (or as many brackets you want), also "(if (not(a)))".
Structure:
or (for more than one command to execute):
Or without the else:
Except the last end there's always a semicolon behind the end. There is never a semicolon before an "Else"!
Example:
You can start and end a string with a quote (') or a double quote ("). How to write a quote or double quote in a string? It would end the string in the middle! If you have to write a quote in the text, you can start and end your string with a double quote or write your quote twice as it has been done at line 8. Do the same thing for a double quote.

### The case structure

The Case structure is quite similar to the if structure with the following difference: You can more easily ask for several cases!
Structure:
But with a case-structure you can only ask for Integers and chars.

## Operators
### Expanding the condition

You can expand your condition with a few operators:
* AND (like && in C): logical 'and': if (a = 1) and (b = 2). The value of the expression "(a = 1) and (b = 2)" is TRUE if a is 1 and b is 2. Else, the value is FALSE and the ELSE-part will be executed (and not the part after THEN). Don't forget the brackets!
* OR (like || in C): 'or': if (a = 1) or (b = 1). If a is 1, b is 1 or both is 1, the value of the expression is TRUE.
* XOR: If only one of the conditions is true: if (a = 1) xor (b = 2). The expression is true if a is 1 or b is 2. If a is 1 AND b is 2, the value will be FALSE!
* NOT: The opposite of the expression.
It's also possible to interlink that operators. But then don't forget the brackets!
By the way: Every condition returns a boolean value. If it is TRUE, the then-part will be executed. If not, the processor goes to the else-part.

### Operators such as 'equals'

Operators such as '=' are:
* = equals
* > greater than
* < less than
* <= less or equals
* >= greater or equals
* <> not equal (less or greater, not the same)
and conjunction or disjunction xor exclusive disjunction

### Operators for calculating

* You can use ( and ) as brackets.
* / means 'divided by', the result is a float
* div means 'divided by', the result is a rounded integer
* * means 'times'
* + means 'plus'
* - means 'minus'
+ also means linking of strings or chars:
* string + string : string
* string + char : string
* char + char : string
* char + string : string
* string + number : error
* number + string : error
* number + number : number
* number + char : error
* char + number : error

## Loops

Loop means: A block will be executed many times. There are four types of loops:

### For-to

The var will count from [start] to [end] and after every counting step the code will be executed. Normally the [var] is defined as i, j or k, but you can also choose counting_var_with_this_name or any name.

### For-downto

The var will count down from [end] to [start] and after every counting step the code will be executed.

### While-do

While the condition is true, the code will be executed. Whether the condition is TRUE or FALSE will be checked BEFORE executing the code.

### Repeat-until

The code will be executed until the condition is true. Whether the condition is TRUE or FALSE will be checked AFTER executing the code.

## Setting values

The operator for setting values is :=
By executing, a will get the value of b.
EXAMPLE:
a equals 1; b equals 3
After executing:
a equals 3; b equals 3
and not:
a equals 1; b equals 1
Be careful with the order!