Statements

SSharp S# API

DropDown image DropDownHover image Collapse image Expand image CollapseAll image ExpandAll image Copy image CopyHover image

A program in S# script is a sequence of statements. There are three common statement types supported: sequencing, looping and branching.

if ... then ... else
 

if (Expression) Statement else Statement

 

For example:

if (x>0) y = y + 1 ; else y = y – 1;
if (x>0) message = 'X is positive';

 

for …

 

for (Expression1;Expression2;Expression3) Statement

For example:

sum=0;
for(i=0; i<10; i++) sum = sum + a[i];

 

while …

 

while (Expression) Statement

For example:

while (i>0) i = i-1;

 

foreach ... in …

 
foreach (Identifier in Expression) Statement

 

Note: The result of Expression calculation must implement IEnumerable. Expression evaluates only once, before loop starts. For example:

arr=![1,2,3,4,5]; sum = 0;
foreach(i in arr ) sum = sum + i;

 

switch

 

switch (Expression)
{
   case expr1: Statement
   ...
   default: Statement
}

 
For example:

 

switch (i)
{
   case : MessageBox.Show('Hello!');
   case : MessageBox.Show('?');
   default: MessageBox.Show('No way');
}

 

using

 
using ( object or type )
{
    . . .
}

 
Example 1:

using (Math)
{
  return Pow(2,10);
}

Example 2:

a = new List< |int|>();
using(a)
{
  Add(10);
  Add(20);
}

return a[0];

 

break, continue

This has usual meaning and can be used only inside a loop.

return

Used only inside function calls.

 

See also: