From Clomosy Docs

(Created page with "This page contains commonly used keywords and directives in the programming language. Keywords form the fundamental building blocks of a programming language and are used to perform specific tasks. Acting as commands, these words manage the control flow, data structures, and other essential operations within a program. The correct use of keywords during programming is crucial for building error-free and efficient code.<br> Below is a list of the main keywords used in th...")
 
No edit summary
Line 7: Line 7:
</div>
</div>


=== '''Begin''' ===
<h2> <b>Begin</b> </h2>
The Begin keyword is fundamental to Clomosy and it starts statement blocks. The begin-end pair fence in a set of statements. You may place such a block anywhere in your code. It is particularly sensible in if and for statements, even if only one statement is required. It means that adding an additional statement in the future is easy.<br>
The Begin keyword is used in the Clomosy platform within the BASE Syntax to start expression blocks. This type of block is used at the beginning of the main block in your code and within conditions, loops, procedures, and function structures.<br>


'''For Example:'''<br>
<b>Example:</b><br>
var
<pre>
valueStr : String;
var
<span style="color:red">Begin</span>
valueStr : String;
  for i := 1 to 10 do
Begin
  <span style="color:red">Begin</span>
  for i := 1 to 10 do
    ShowMessage('Number: '+IntToStr(i));
  Begin
  end;
    ShowMessage('Number: '+IntToStr(i));
end;
  end;
end;
</pre>


=== '''End''' ===
<h2> <b>End</b> </h2>
The End keyword is fundamental to Clomosy - it terminates statement blocks. The most common is :
The End keyword is used in the Clomosy platform within the BASE Syntax to terminate expression blocks. This type of block is used at the end of the main block in your code and within conditions, loops, procedures, and function structures.<br>
   
   
Begin
<b>Example:</b><br>
  ??... statements ...
<pre>
<span style="color:red">End;</span>
var
  i : Integer;


'''For Example:'''<br>
begin
var
  i := 2;
  i : Integer;<br>
begin
  i := 2;<br>
  case i of
    0 : Showmessage('i = 0');
    1 : Showmessage('i = 1');
    2 : Showmessage('i = 2');
  <span style="color:red">End;</span>
<span style="color:red">End;</span>


=== '''var''' ===
  case i of
The Var keyword is used to start a section of variable definitions.
    0 : Showmessage('i = 0');
    1 : Showmessage('i = 1');
The section is terminated by the next keyword in a program.
    2 : Showmessage('i = 2');
   
  End;
Within the section, one or more variables may be defined. These can be of any data type.
End;
</pre>
 
<h2> <b>var</b> </h2>
The var keyword is used for defining variables. To create a variable, var is used to specify the name and type of the variable. This keyword allocates memory in the program to store a specific data type.<br>
 
<b>Example:</b><br>
<b>TRObject Syntax</b><br>
<pre>
Var
  appName  : String;
  year : Integer;
{
  appName = 'Clomosy';
  year = 2023;
 
  ShowMessage('appName = '+appName );
  ShowMessage('Year = '+IntToStr(year));
}
</pre>
<b>Base Syntax</b><br>
<pre>
Var
  appName  : String;
  year : Integer;
begin
  appName    := 'Clomosy';
  year := 2023;


'''For Example:'''<br>
  ShowMessage('appName = '+appName  );
<span style="color:red">Var</span>
  ShowMessage('Year = '+IntToStr(year));
  namee : String;
end;
  year : Integer;
</pre>
begin
  namee  := 'Clomosy';
  year := 2023;
  ShowMessage('Name  = '+namee);
  ShowMessage('Year = '+IntToStr(year));
end;


=== '''And''' ===
<h2> <b>And</b> </h2>
The and keyword is used as a logical operator in the BASE syntax structure of the Clomosy platform. It is used to combine two or more conditions and returns a true value only when all conditions are true. In other words, if all expressions combined with and are true, the result is true; otherwise, it is false.<br>
The And keyword is used in two different ways:<br>
The And keyword is used in two different ways:<br>
1. To perform a logical or boolean 'and' of two logical values. If both are true, then the result is true, otherwise, the result is false.<br>
1. To perform a logical or boolean 'and' of two logical values. If both are true, then the result is true, otherwise, the result is false.
2. To perform a mathematical 'and' of two integers. The result is a bitwise 'and' of the two numbers. For example:<br>
2. To perform a mathematical 'and' of two integers. The result is a bitwise 'and' of the two numbers. For example:
   
   
10110001 '''And''' 01100110 = 00100000
10110001 '''And''' 01100110 = 00100000


'''For Example:'''<br>
<b>Example</b>
 
<pre>
var
  num1, num2, num3 : Integer;
  letter          : Char;
 
begin
  num1  := $25;   
  num2  := $10;   
  letter := 'G';
 
  if (num1 > 0) And (letter = 'G')
  then ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');
 
  num3 := num1 And num2;
 
  ShowMessage('25 And 32 = '+ IntToStr(num3));
end;
</pre>
 
 
  var
  var
   num1, num2, num3 : Integer;
   num1, num2, num3 : Integer;

Revision as of 09:00, 27 September 2024

This page contains commonly used keywords and directives in the programming language. Keywords form the fundamental building blocks of a programming language and are used to perform specific tasks. Acting as commands, these words manage the control flow, data structures, and other essential operations within a program. The correct use of keywords during programming is crucial for building error-free and efficient code.

Below is a list of the main keywords used in the programming language. Understanding these keywords will help you grasp the structure of the language and use the correct syntax when developing software.

Begin

The Begin keyword is used in the Clomosy platform within the BASE Syntax to start expression blocks. This type of block is used at the beginning of the main block in your code and within conditions, loops, procedures, and function structures.

Example:

var
valueStr : String;
Begin
  for i := 1 to 10 do
  Begin
    ShowMessage('Number: '+IntToStr(i));
  end;
end;

End

The End keyword is used in the Clomosy platform within the BASE Syntax to terminate expression blocks. This type of block is used at the end of the main block in your code and within conditions, loops, procedures, and function structures.

Example:

var
  i : Integer;

begin
  i := 2;

  case i of
    0 : Showmessage('i = 0');
    1 : Showmessage('i = 1');
    2 : Showmessage('i = 2');
  End;
End;

var

The var keyword is used for defining variables. To create a variable, var is used to specify the name and type of the variable. This keyword allocates memory in the program to store a specific data type.

Example:
TRObject Syntax

Var
  appName   : String;
  year : Integer;
{
  appName = 'Clomosy';
  year = 2023; 

  ShowMessage('appName = '+appName  );
  ShowMessage('Year = '+IntToStr(year));
}

Base Syntax

Var
  appName   : String;
  year : Integer;
begin
  appName    := 'Clomosy';
  year := 2023; 

  ShowMessage('appName = '+appName  );
  ShowMessage('Year = '+IntToStr(year));
end;

And

The and keyword is used as a logical operator in the BASE syntax structure of the Clomosy platform. It is used to combine two or more conditions and returns a true value only when all conditions are true. In other words, if all expressions combined with and are true, the result is true; otherwise, it is false.
The And keyword is used in two different ways:
1. To perform a logical or boolean 'and' of two logical values. If both are true, then the result is true, otherwise, the result is false.
2. To perform a mathematical 'and' of two integers. The result is a bitwise 'and' of the two numbers. For example:

10110001 And 01100110 = 00100000

Example

var
  num1, num2, num3 : Integer;
  letter           : Char;

begin
  num1   := $25;    
  num2   := $10;    
  letter := 'G';

  if (num1 > 0) And (letter = 'G')
  then ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');

  num3 := num1 And num2;

  ShowMessage('25 And 32 = '+ IntToStr(num3));
end;


var
  num1, num2, num3 : Integer;
  letter           : Char;
begin num1  := $25; num2  := $10; letter := 'G';
if (num1 > 0) And (letter = 'G') then ShowMessage('Both values are true') else ShowMessage('None or only one true value');
num3 := num1 And num2;
ShowMessage('25 And 32 = '+ IntToStr(num3)); end;


Not

The Not keyword is used in two different ways:
1. To perform a logical or boolean 'Not' of a logical value.If True, the value becomes False. If False, the value becomes True.

2. To perform a mathematical 'Not' of an integer in a bitwise fashion. The result is a bitwise 'Not' of the number - every bit value is reversed - 0 to 1 and 1 to 0.

For Example:

var
  num1, num2 : Word;
begin num1  := $2C; // Binary value : 0000 0000 0010 1100 // Not'ed value : 1111 1111 1101 0011 = $FFD3
// And used to return a Boolean value if Not (num1 > 0) then ShowMessage('num1 <= 0') else ShowMessage('num1 > 0');
// And used to perform a mathematical NOT operation num2 := Not num1;
// Display the result ShowMessage('Not $2C = $'+IntToHex(num2,2));
end;


Or

The Or keyword is used in two different ways:

1. To perform a logical or boolean 'or' of two logical values. If either are true, then the result is true, otherwise it is false.

2. To perform a mathematical 'or' of two integers. The result is a bitwise 'or' of the two numbers. For example:

10110001 Or 01100110 = 11110111

For Example:

var
  num1, num2, num3 : Integer;
  letter           : Char;
begin num1  := $25; num2  := $10; letter := 'G';
if (num1 > 0) Or (letter = 'G') then ShowMessage('Both values are true') else ShowMessage('None or only one true value');
num3 := num1 Or num2;
ShowMessage('25 And 32 = '+ IntToStr(num3)); end;

Xor

The Xor keyword is used in two different ways:

1. To perform a logical or boolean 'Exclusive-or' of two logical values. If they are different, then the result is true.

2. To perform a mathematical 'Exclusive-or' of two integers. The result is a bitwise 'Exclusive-or' of the two numbers. For example:

10110001 Xor 01100110 = 11010111

For Example:

var
  num1, num2, num3 : Integer;
  letter           : Char;
begin num1  := $25; num2  := $10; letter := 'G';
if (num1 > 0) Xor (letter = 'G') then ShowMessage('Both values are true') else ShowMessage('None or only one true value');
num3 := num1 Xor num2;
ShowMessage('25 And 32 = '+ IntToStr(num3)); end;

Array

The Array provides single and multi dimensional arrays (indexable sequences) of data. Dynamic arrays have no preallocated storage. When defined, only a pointer is created. For detailed information, visit the page.

As

The as keyword is used to assign objects or interfaces of one type to another.

Case

The Case keyword provides a structured equivalent to a sequence of if statements on the same variable. The case statement is more elegant, more efficient, and easier to maintain than multiple if nestings.The brief definition is as follows.

case condition of
   condition1: //lines of code
   condition2: //lines of code
   condition3: //lines of code
   condition4: //lines of code

else
   //lines of code
End;

For detailed information, see the page.

Const

The Const keyword is used to start a section of constant definitions. The section is terminated by the next keyword in a program. Within the section, one or more constants may be defined. These can be a mixture of normal or typed constants.

const
   variableName = dataAssignment;
const
    pi = 3.14;


Div

The Div keyword gives the whole number result of dividing the Dividend by the Divisor. Any remainder is discarded.

Dividend div divisor

For detailed information, see the page.

Do

The Do keyword is always a part of one of the shown 3(with - for - while)control types. It precedes the Statements section of the control action.

Example:

with Expression do Statement

With AddImg do begin
      Height := 70;
      Align := alRight;
      Margins.Right:=50;
end;

for Variable := Expression to Expression do Statement;

 for j := beginning to finish do
 begin
       //lines of code
 end;

while Expression do Statement

while first<=end do	//if the situation is true
begin
    //lines of code
end;

downto

The DownTo keyword prefixes the target value Expression in a For loop. The DownTo expression maybe an Integer, Character or Enumeration type.

See the For keyword for full details. The examples illustrate the three expression types.

1 for Variable := Integer Expression downto Integer Expression do Statement; 2 for Variable := Char Expression downto Char Expression do Statement; 3 for Variable := Enum Expression downto Enum Expression do Statement;

 for j := beginning downto finish  do
 begin
        //lines of code
 end;

else

The Else keyword is part of the If, Case and Try statements. It is used to start the section of code executed when earlier conditions are not satisfied. See details of each of these statements for further details. (for, case)

1 keyword Else(if Condition then Statement else Statement;
2 case Expression of
Case clauses
...
else
Statements
end;
3 try
Statements
...
except
Exception statements
...
else
Statements
end

Try

The Try keyword is used to mark the start of a block of statements that have error trapping. If an error occurs, the program is not terminated. Instead, control is passed to either a Finally or Except section.

For example:

var
  number, zero : Integer;
begin
  number := -1;
  Try
    zero   := 0;
    number := 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  finally
      ShowMessage('Number was not assigned a value - using default');
  end;
end;

except

The Except keyword is used to mark the start of a block of statements that handle an exception in a Try clause. If the Except block can handle the exception, then the program is not terminated.

try
....
....
code to be executed under normal conditions.
...
..
except
...
..
code to be executed under normal circumstances, and code to be executed when an exception occurs during the execution of the normal code.
..
.
end;

Example:

var
  number, zero : Integer;
begin
  // Try to divide an integer by zero - to raise an exception
  Try
    zero   := 0;
    number := 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  Except
    ShowMessage('Unknown error encountered');
  end;
end;

finally

The Finally keyword is used to mark the start of the final block of statements in a Try statement. They are executed regardless of what happens in the Try statements. However, the Finally clause does not actually handle any exceptions - the program will terminate if no Except clause is found (see notes below).

Try-Finally is normally used by a routine to allow cleanup processing to take place, such as freeing resources, with the exception being correctly passed to the caller to handle.

try
....
....
code to be executed under normal conditions.
...
..
finally
...
..
Commands to be executed no matter what
..
.
end;

Example:

var
  number, zero : Integer;
begin
  // Try to divide an integer by zero - to raise an exception
  number := -1;
  Try
    zero   := 0;
    number := 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  Finally
    if number = -1 then
    begin
      ShowMessage('Number was not assigned a value - using default');
      number := 0;
    end;
  end;
end;

Output: Number was not assigned a value - using default
Then, the program terminates with an not division by zero when evaluating runtime error message - the finally clause did not trap the error.
If you want it to work without errors, change the value of the zero variable.

Repeat

The Repeat keyword starts a control loop that is always executed at least once, and which terminates when the Expression is satisfied (returns True).

There is no need for Begin or End markers - the Repeat and Until keywords serve that purpose.

It is used when it is important that the statements are at least executed once.

Until

The Until keyword ends a control loop that is always executed at least once, and which terminates when the Expression is satisfied (returns True).

There is no need for Begin or End markers - the Repeat and Until keywords serve that purpose.

It is used when it is important that the statements are at least executed once.

for

The For keyword starts a control loop, which is executed a finite number of times.

The Variable is set to the result of the 1st Expression. If the result is less than or equal to the result of the 2nd Expression (when to is specified), then the Statement is executed. Variable is then incremented by 1 and the process is repeated until the variable value exceeds the 2nd expression value.

For downto, the variable value is checked as being greater than or equal to the 2nd expression, and its value is decremented at the loop end. The Statement maybe a single line, or a set of statements with a begin/end block.

Example:

var
  i : Integer;

begin
  // Loop 5 times
  For i := 1 to (10 div 2) do
    ShowMessage('i = '+IntToStr(i));
end;

while

The While keyword starts a control loop that is executed as long as the Expression is satisfied (returns True).

The loop is not executed at all if the expression is false at the start.

You need Begin or End markers if multiple statements are required in the loop. See the While keyword for full details.

with

The With keyword is a convenience provided by Clomosy for referencing elements of a complex variable, such as a record or object.

It simplifies the code by removing the need to prefix each referenced element with the complex variable name. See the With keyword for full details.

to

The To keyword prefixes the target value Expression in a For loop. The To expression maybe an Integer, Character or Enumeration type. See the For keyword for full details.

Function

The Function keyword defines a subroutine that returns a value. See the SubRoutines tutorial for details on using functions. See page for detailed information.

Procedure

The Procedure keyword defines a subroutine that does not return a value. See the Procedure tutorial for details on using procedures.

if

The If keyword is used to control the flow of code depending on the logical result of the given condition. See page for detailed information.

then

The Then keyword is part of the If statement. It is used to start the section of code executed when the if condition is true.See the if keyword for full details.


mod

The Mod keyword gives the remainder from dividing the Dividend by the Divisor. The whole number result of the division is ignored. See page for detailed information.