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
 
(8 intermediate revisions by 2 users not shown)
Line 7: Line 7:
</div>
</div>


=== '''Begin''' ===
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>


'''For Example:'''<br>
<h2> <b>var</b> </h2>
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.<br>
valueStr : String;
<span style="color:red">Begin</span>
  for i := 1 to 10 do
  <span style="color:red">Begin</span>
    ShowMessage('Number: '+IntToStr(i));
  end;
end;


=== '''End''' ===
<b>Example:</b><br>
The End keyword is fundamental to Clomosy - it terminates statement blocks. The most common is :
Begin
  ??... statements ...
<span style="color:red">End;</span>


'''For Example:'''<br>
<pre>
var
Var
  i : Integer;<br>
  appName  : String;
begin
  year : Integer;
  i := 2;<br>
{
  case i of
  appName = 'Clomosy';
    0 : Showmessage('i = 0');
  year = 2023;  
    1 : Showmessage('i = 1');
    2 : Showmessage('i = 2');
  <span style="color:red">End;</span>
<span style="color:red">End;</span>


=== '''var''' ===
  ShowMessage('appName = '+appName  );
The Var keyword is used to start a section of variable definitions.
  ShowMessage('Year = '+IntToStr(year));
}
The section is terminated by the next keyword in a program.
</pre>
Within the section, one or more variables may be defined. These can be of any data type.


'''For Example:'''<br>
<h2> <b>Xor</b> </h2>
<span style="color:red">Var</span>
As a logical operator, xor combines two or more conditions and checks whether only one of them is true. If only one of the conditions combined with xor is true, the result will be true; however, if both conditions are true or both are false, the result will be false. This operator is useful for expressing the logic of "either one or the other" between conditions.<br>
  namee : String;
  year : Integer;
begin
  namee  := 'Clomosy';
  year := 2023;
  ShowMessage('Name  = '+namee);
  ShowMessage('Year = '+IntToStr(year));
end;


=== '''And''' ===
<b>Example</b><br>
The And keyword is used in two different ways:<br>
<pre>
var
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.
  num1, num2, num3 : Integer;
  letter          : Char;
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


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


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


=== '''Not''' ===
  num3 = num1 Xor num2;
The Not keyword is used in two different ways:<br>
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.
  ShowMessage('25 And 32 = '+ IntToStr(num3));
}
</pre>


'''For Example:'''<br>
<h2> <b>Not</b> </h2>
It is used as a logical operator to negate a condition; that is, the not operator evaluates a condition as false if it is true, and as true if it is false. This way, it is useful for altering the logical states of conditions.<br>


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


<pre>
var
  num1, num2 : Word;


=== '''Or''' ===
{
The Or keyword is used in two different ways:<br>
  num1  = $2C;    // Binary value : 0000 0000 0010 1100
                  // Not'ed value : 1111 1111 1101 0011 = $FFD3


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.
  // And used to return a Boolean value
  if Not (num1 > 0)
    ShowMessage('num1 <= 0')
  else ShowMessage('num1 > 0');


2. To perform a mathematical 'or' of two integers. The result is a bitwise 'or' of the two numbers. For example:
  // And used to perform a mathematical NOT operation
  num2 = Not num1;


10110001 Or 01100110 = 11110111
  // Display the result
  ShowMessage('Not $2C = $'+IntToHex(num2,2));
}
</pre>


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


=== '''Xor''' ===
<h2> <b>Array</b> </h2>
The Xor keyword is used in two different ways:<br>
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:'''<br>
var
  num1, num2, num3 : Integer;
  letter          : Char;<br>
begin
  num1  := $25;   
  num2  := $10;   
  letter := 'G';<br>
  if (num1 > 0) <span style="color:red">Xor</span> (letter = 'G')
  then ShowMessage('Both values are true')
  else ShowMessage('None or only one true value');<br>
  num3 := num1 <span style="color:red">Xor</span> num2;<br>
  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 [[Arrays | page]].
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 [[Arrays | page]].


=== '''As''' ===
<h2> <b>As</b> </h2>
The as keyword is used to assign objects or interfaces of one type to another.
The as keyword is used for type casting. It is particularly useful in object-oriented programming when a object needs to be converted from one type to another. This operation should only be performed between compatible types; otherwise, an error will occur.


=== '''Case''' ===
<h2> <b>Case</b> </h2>
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.  
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'''
<b>Example</b><br>
    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 [https://www.docs.clomosy.com/index.php/Clomosy_Language#Case_Statements page].
<pre>
var
  day: Integer;
  dayName: String;
{
  day = 3; // Example day number


=== '''Const''' ===
  case day of
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.
  {
    1: dayName = 'Monday';
    2: dayName = 'Tuesday';
    3: dayName = 'Wednesday';
    4: dayName = 'Thursday';
    5: dayName = 'Friday';
    6: dayName = 'Saturday';
    7: dayName = 'Sunday';
  else
    dayName = 'Invalid day'; // If the given day number is not between 1-7
  }
 
  ShowMessage('Day: ' + dayName);
}
</pre>


const
<h2> <b>Const</b> </h2>
    variableName = dataAssignment;
The const keyword is used to define constant values. Constants are values that remain unchanged during the execution of the program. A constant defined with const takes a value of a specific type, and this value cannot be altered after its declaration. This feature enhances the reliability and readability of the code.<br>


const
<pre>
    pi = 3.14;
const
    pi = 3.14;
</pre>


 
<h2> <b>Div</b> </h2>
=== '''Div''' ===
The Div keyword gives the whole number result of dividing the Dividend by the Divisor. Any remainder is discarded.
The Div keyword gives the whole number result of dividing the Dividend by the Divisor. Any remainder is discarded.
  Dividend '''div''' divisor
  Dividend div divisor


For detailed information, see the [https://www.docs.clomosy.com/index.php/Div page].
For detailed information, see the [[Div |page]].


=== '''Do''' ===
<h2> <b>downto</b> </h2>
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:'''<br>
It is used to indicate that the count in a loop should be done in decreasing order. The loop variable progresses from a specified starting value to an end value by decreasing.<br>


with Expression do Statement
<b>Example</b><br>
With AddImg '''do''' begin
      Height := 70;
      Align := alRight;
      Margins.Right:=50;
end;


for Variable := Expression to Expression do Statement;
<pre>
   for j := beginning to finish '''do'''
var
   begin
  i: Integer;
        //lines of code
{
  end;
  // Counting down from 5 to 1
   for (i = 5 downto 1)
  {
    ShowMessage('i = ' + IntToStr(i));
   }
}
</pre>


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


=== '''downto''' ===
<h2> <b>Else</b> </h2>


The DownTo keyword prefixes the target value Expression in a For loop. The DownTo expression maybe an Integer, Character or Enumeration type.
The Else keyword is part of the If and Case statements. It is used to start the section of code executed when earlier conditions are not satisfied.<br>
See the For keyword for full details. The examples illustrate the three expression types.


1 for Variable := Integer Expression '''downto''' Integer Expression do Statement;
<b> If for; </b><br>
2 for Variable := Char Expression '''downto''' Char Expression do Statement;
<pre>
3 for Variable := Enum Expression '''downto''' Enum Expression do Statement;
var
  score: Integer;
{
  score = 75;
 
  if (score >= 50)
    ShowMessage('Passed')
  else
    ShowMessage('Failed');
}
</pre>


  for j := beginning downto finish  do
<b> Case for; </b><br>
   begin
<pre>
        //lines of code
var
   end;
   choice: Integer;
{
   choice = 1;


=== '''else''' ===
  case choice of
  {
    0: ShowMessage('Choice 0');
  else
    ShowMessage('Invalid choice');
  }
}
</pre>


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.
<h2> <b>Try</b> </h2>
([https://www.docs.clomosy.com/index.php/Clomosy_Language#If_Statements for], [https://www.docs.clomosy.com/index.php/Clomosy_Language#Case_Statements case])<br>
It is used for error handling and management. The try block ensures the safe execution of a specific piece of code. If an error occurs within the try block, the error can be caught and handled by the <b>except or finally</b> blocks.<br>


:1 keyword '''Else'''(if Condition then Statement else Statement;<br>
<b>Example</b><br>


:2 case Expression of
<pre>
::Case clauses<br>
var
::...<br>
  number, zero : Integer;
::'''else'''<br>
{
::Statements<br>
  number = -1;
::end;<br>
  Try
    zero  = 0;
    number = 1 div zero;
    ShowMessage('number / zero = '+IntToStr(number));
  finally
      ShowMessage('Number was not assigned a value - using default');
  }
}
</pre>


:3 try <br>
<h2> <b>Except</b> </h2>
::Statements<br>
::...<br>
::except<br>
::Exception statements<br>
::...<br>
::'''else'''<br>
::Statements<br>
::end<br>


=== '''Try'''===
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.<br>
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 more detailed information, see the [[Error Trapping| page]].


'''For example:'''<br>
<h2> <b>Finally</b> </h2>
var
Regardless of whether an error occurs in the try block, the code in the finally block always executes. This is useful to ensure that important tasks, such as resource deallocation or cleanup operations, are always carried out.<br>
  number, zero : Integer;
For more detailed information, see the [[Error Trapping| page]].
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''' ===
<h2> <b>Repeat</b> </h2>
The repeat keyword allows a block of code to be repeated until a specific condition is met. It is used in conjunction with the until keyword to check the loop condition. This structure ensures that the code within the loop is executed at least once.<br>


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.
<h2> <b>Until</b> </h2>
The until keyword is used in conjunction with the repeat statement to define the condition that terminates the loop. The loop continues to execute until the specified condition evaluates to true. This means that the block of code will keep running until the condition becomes true, making it useful for scenarios where you want the code to execute at least once before checking the condition.<br>


try
<b>Example</b><br>
....
....
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:'''<br>
<pre>
var
var
  number, zero : Integer;
  counter: Integer;
begin
{
  // Try to divide an integer by zero - to raise an exception
   counter = 1;
  Try
  repeat
    zero   := 0;
    ShowMessage('Counter: ' + IntToStr(counter));
    number := 1 div zero;
    counter = counter + 1;
    ShowMessage('number / zero = '+IntToStr(number));
  until counter > 5;
  Except
}
    ShowMessage('Unknown error encountered');
</pre>
  end;
end;


=== '''finally''' ===
<h2> <b>For</b> </h2>
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).
The for structure is a control structure used to create a loop under a specific condition. It is ideal for performing a certain number of repetitions or iterating over an array. A for loop typically starts with a variable at a beginning value and progresses to an end value, with a specific increment or decrement on each iteration.<br>
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
<b>Example</b><br>
....
....
code to be executed under normal conditions.
...
..
finally
...
..
Commands to be executed no matter what
..
.
end;


'''Example:'''<br>
<pre>
var
var
  number, zero : Integer;
  i : Integer;
begin
{
  // Try to divide an integer by zero - to raise an exception
   For (i = 1 to 6)
  number := -1;
    ShowMessage('i = '+IntToStr(i));
  Try
}
    zero   := 0;
</pre>
    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<br>
Then, the program terminates with an not division by zero when evaluating runtime error message - the finally clause did not trap the error. <br>
If you want it to work without errors, change the value of the zero variable.


=== '''Repeat'''===
<h2> <b>While</b> </h2>
The Repeat keyword starts a control loop that is always executed at least once, and which terminates when the Expression is satisfied (returns True).
The while keyword is a control structure used to repeatedly execute a block of code as long as a specific condition is met. This loop continues to run as long as the condition evaluates to true. Due to the fact that the condition is evaluated before entering the loop, it guarantees that the code within the loop may not execute at all if the condition is not satisfied. This is useful for avoiding infinite loops and ensuring a specific state is achieved.<br>
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'''===
<b>Example</b><br>
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:'''<br>
<pre>
var
var
  i : Integer;
  count: Integer;
{
begin
  count = 0;
  // Loop 5 times
  while (count < 5)
  For i := 1 to (10 div 2) do
  {
    ShowMessage('i = '+IntToStr(i));
    ShowMessage('Count: ' + IntToStr(count));
end;
    count = count + 1;
  }
}
</pre>


=== '''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 [[TRObject_Language#While_Statements | While]] keyword for full details.


=== '''with''' ===
<h2> <b>With</b> </h2>
The With keyword is a convenience provided by Clomosy for referencing elements of a complex variable, such as a record or object.
The With keyword is a convenience provided by Clomosy for referencing elements of a complex variable, such as a record or object.
   
   
Line 391: Line 268:
See the [[TRObject_Language#With_Statements | With]] keyword for full details.
See the [[TRObject_Language#With_Statements | With]] keyword for full details.


=== '''to''' ===
<h2> <b>Function</b> </h2>
The To keyword prefixes the target value Expression in a For loop. The To expression maybe an Integer, Character or Enumeration type. See the [[TRObject_Language#For_Statements | For]] keyword for full details.


=== '''Function''' ===
The Function keyword is used to define a function that performs a specific operation and returns a value in a programming language. Functions allow code to be modular, providing the ability to reuse the same operation in different places. See [[TRObject_Language#Function_Declarations | page]] for detailed information.


The Function keyword defines a subroutine that returns a value. See the SubRoutines tutorial for details on using functions. See [[TRObject_Language#Function_Declarations | page]] for detailed information.
<h2> <b>Void</b> </h2>
It is used to define a procedure in a programming language that performs a specific task and does not return a value. See the [[TRObject_Language#Procedures]] tutorial for details on using void.


=== '''Procedure''' ===
<h2> <b>If</b> </h2>
The Procedure keyword defines a subroutine that does not return a value. See the [[TRObject_Language#Procedure_Declarations | 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 [[TRObject_Language#If_Statements | page]] for detailed information.
The If keyword is used to control the flow of code depending on the logical result of the given condition. See [[TRObject_Language#If_Statements | 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 [[TRObject_Language#If_Statements | if]] keyword for full details.


<h2> <b>Mod</b> </h2>
The Mod keyword gives the remainder from dividing the Dividend by the Divisor. The whole number result of the division is ignored.
See [[Mod | page]] for detailed information.<br><br>


=== '''mod''' ===
<div class="alert alert-success" role="alert" data-bs-theme="light">
The Mod keyword gives the remainder from dividing the Dividend by the Divisor. The whole number result of the division is ignored.
For more detailed information, please refer to the [[TRObject Language | TRObject Language]] page.
See [[Mod | page]] for detailed information.
</div>
{{#seo:|title=Keywords Found in Clomosy - Clomosy Docs}}
{{#seo:|description=Explore essential keywords in Clomosy to manage control flow, data structures, and operations, ensuring efficient and error-free application development.}}

Latest revision as of 15:04, 24 December 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.


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:

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

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

Xor

As a logical operator, xor combines two or more conditions and checks whether only one of them is true. If only one of the conditions combined with xor is true, the result will be true; however, if both conditions are true or both are false, the result will be false. This operator is useful for expressing the logic of "either one or the other" between conditions.

Example

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

{
  num1   = $25;    
  num2   = $10;    
  letter = 'G';

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

  num3 = num1 Xor num2;

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

Not

It is used as a logical operator to negate a condition; that is, the not operator evaluates a condition as false if it is true, and as true if it is false. This way, it is useful for altering the logical states of conditions.

Example

var
  num1, num2 : Word;

{
  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)
    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));
}


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 for type casting. It is particularly useful in object-oriented programming when a object needs to be converted from one type to another. This operation should only be performed between compatible types; otherwise, an error will occur.

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.

Example

var
  day: Integer;
  dayName: String;
{
  day = 3; // Example day number

  case day of
  {
    1: dayName = 'Monday';
    2: dayName = 'Tuesday';
    3: dayName = 'Wednesday';
    4: dayName = 'Thursday';
    5: dayName = 'Friday';
    6: dayName = 'Saturday';
    7: dayName = 'Sunday';
  else
    dayName = 'Invalid day'; // If the given day number is not between 1-7
  }
  
  ShowMessage('Day: ' + dayName);
}

Const

The const keyword is used to define constant values. Constants are values that remain unchanged during the execution of the program. A constant defined with const takes a value of a specific type, and this value cannot be altered after its declaration. This feature enhances the reliability and readability of the code.

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.

downto

It is used to indicate that the count in a loop should be done in decreasing order. The loop variable progresses from a specified starting value to an end value by decreasing.

Example

var
  i: Integer;
{
  // Counting down from 5 to 1
  for (i = 5 downto 1)
  {
    ShowMessage('i = ' + IntToStr(i));
  }
}


Else

The Else keyword is part of the If and Case statements. It is used to start the section of code executed when earlier conditions are not satisfied.

If for;

var
  score: Integer;
{
  score = 75;
  
  if (score >= 50)
    ShowMessage('Passed')
  else
    ShowMessage('Failed');  
}

Case for;

var
  choice: Integer;
{
  choice = 1;

  case choice of
  {
    0: ShowMessage('Choice 0');
  else
    ShowMessage('Invalid choice');
  }
}

Try

It is used for error handling and management. The try block ensures the safe execution of a specific piece of code. If an error occurs within the try block, the error can be caught and handled by the except or finally blocks.

Example

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

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.
For more detailed information, see the page.

Finally

Regardless of whether an error occurs in the try block, the code in the finally block always executes. This is useful to ensure that important tasks, such as resource deallocation or cleanup operations, are always carried out.
For more detailed information, see the page.

Repeat

The repeat keyword allows a block of code to be repeated until a specific condition is met. It is used in conjunction with the until keyword to check the loop condition. This structure ensures that the code within the loop is executed at least once.

Until

The until keyword is used in conjunction with the repeat statement to define the condition that terminates the loop. The loop continues to execute until the specified condition evaluates to true. This means that the block of code will keep running until the condition becomes true, making it useful for scenarios where you want the code to execute at least once before checking the condition.

Example

var
  counter: Integer;
{
  counter = 1;
  repeat
    ShowMessage('Counter: ' + IntToStr(counter));
    counter = counter + 1;
  until counter > 5;
}

For

The for structure is a control structure used to create a loop under a specific condition. It is ideal for performing a certain number of repetitions or iterating over an array. A for loop typically starts with a variable at a beginning value and progresses to an end value, with a specific increment or decrement on each iteration.

Example

var
  i : Integer;
{
  For (i = 1 to 6)
    ShowMessage('i = '+IntToStr(i));
}


While

The while keyword is a control structure used to repeatedly execute a block of code as long as a specific condition is met. This loop continues to run as long as the condition evaluates to true. Due to the fact that the condition is evaluated before entering the loop, it guarantees that the code within the loop may not execute at all if the condition is not satisfied. This is useful for avoiding infinite loops and ensuring a specific state is achieved.

Example

var
  count: Integer;
{
  count = 0;
  while (count < 5)
  {
    ShowMessage('Count: ' + IntToStr(count));
    count = count + 1;
  }
}


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.

Function

The Function keyword is used to define a function that performs a specific operation and returns a value in a programming language. Functions allow code to be modular, providing the ability to reuse the same operation in different places. See page for detailed information.

Void

It is used to define a procedure in a programming language that performs a specific task and does not return a value. See the TRObject_Language#Procedures tutorial for details on using void.

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.


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.