Methods

Proteus methods are declarations, control structures and procedures that do not return any value; every line in a program can have at most one method, taken from the following list:

The methods between '[' and ']' can appear only if, in a previous line, there is a matching occurrence of the method out of the brackets at the beginning of the line.

CONTINUE and BREAK can appear inside WHILE, REPEAT and FOR; since they do a similar function in all three cases, they share the same name; CONTINUE passes control directly to the beginning of the inner WHILE, REPEAT or FOR, skipping all the methods that would follow in natural order; BREAK passes control to the first instruction following the end of the inner WHILE, REPEAT or FOR.

For each line, a single method can be specified:

; Right
IF Test
  SET Result = "True"
ELSE
  SET Result = "False"
FI 
; Wrong
IF Test SET Result = "True"
ELSE SET Result = "False" FI 

Indentation is arbitrary: the user can change it at will; anyway, we suggest to follow the style expressed in the examples in this manual, to keep the code readable. The number of spaces/tabs that separate the parameters is not meaningful.

It is possible to begin a line with a function (null method), but not with a variable name, a string or a number (obviously). The only exception is represented by SET, which can be implicit; in this case, it is compulsory to keep the symbol '=' between the start of the line and the expression to be assigned, in this way:

; Right
S = "This is a string"

; Right
SET S = "This is a string"

; Right
SET S "This is a string"

; Wrong: '=' omitted
S "This is a string"

Below you will find a short description of the other methods, with the exception of FUNCTION (which is described in the chapter about UDF) and CONST / TEXT (described in the chapter about constants):

WHILE [nExpr]
  [method
  [method..]]
  [CONTINUE | BREAK]
LOOP 

The methods between WHILE and LOOP are executed until nExpr becomes false. The value of nExpr is evaluated as follows: 0 = false, other = true. CONTINUE skips all the methods until LOOP and tests nExpr; BREAK does the same thing, but jumps out of the loop, without evaluating nExpr.

REPEAT
  [method
  [method..]]
  [CONTINUE | BREAK]
UNTIL nExpr 

The methods between REPEAT and UNTIL are executed until nExpr becomes true; all the methods are executed at least once. The value nExpr is evaluated as follows: 0 = false, other = true. CONTINUE skips all the methods and tests nExpr; BREAK does the same thing, but jumps out of the loop, without evaluating nExpr.

FOR id [=] nExp1 TO nExp2 [STEP nExp3]
  [method]
  [method..]
  [CONTINUE | BREAK]
NEXT 

id is set to nExp1, then all the methods between FOR and NEXT are repeated until id becomes greater than (or lesser than) nExp2, according to the sign of nExp3; every time NEXT is reached, nExp3 is added to id; if the part beginning with STEP is omitted, id is increased by 1. If nExp3 is positive, nExp1 must be <= nExp2; if nExp3 is negative, nExp1 must be >= nExp2. CONTINUE skips all the methods until NEXT, increase id and tests the exit condition; BREAK jumps out of the loop, without increasing id or evaluating the exit condition.

SWITCH expr [func]
  ON[C] exp1_1[, exp1_2..]
    [method..]
  [ON[C] exp2_1[, exp2_2..]
    [method..]]
  [OTHER
    [method..]]
OFF 

For each ON/ONC, tests if func(expr, expX) is true (not equal to 0); if more than one expression follows ON/ONC, the corresponding methods are executed if at least one of the expressions is true; all the expressions are evaluated in the order in which they appear, from left to right. In case of ON, the execution continues from the method following OFF; in case of ONC, it continues with the body of the next case, until the end of the body of the following ON/OTHER case or until OFF (if there are no other cases).

Example

SET X = 1
SWITCH X
  ONC 1, 2, 3
    CONSOLELN "Print this one.."
  ONC 4
    CONSOLELN "and this.."
  ON 5
    CONSOLELN "and this (last)"
  ONC 6
    CONSOLELN "This is not printed"
OFF

func can be an UDF or any library function accepting two parameters (e.g. EQ, STREQ, IN); if it is not specified, EQ is used by default.
There must always be at least one ON or ONC (obviously).
If the case OTHER appears, it must be right before OFF; the methods in its body are executed only in the case no other expression is true (or as a result of a cascaded execution).

IF nExpr
  [method
  [method..]]
[ELSE
  [method
  [method..]]]
FI 

If nExpr is true, all the methods following IF and preceding ELSE are executed; if it is false, the methods executed are those between ELSE and FI; both the methods in the first block and the 'else' branch can be omitted.

SET id [=] expr 
[SET] id = expr 

Set id to expr; if id does not exist, it is added to the list of valid variables; it is possible to set multiple variables to the same value with SET id1 [=] id2 = id3 .. = expr; in this case, the symbol '=' must always be specified and all the symbols to the left of  each '=' must be variable names. SET can also be omitted if the symbol '=' appears.

PSET id [=] expr
[PSET] id = expr 

Works as SET, but can be used to set public variables inside functions. It can appear only inside an UDF. PSET can be used to set multiple public variables to the same value: all the symbols to the left of a '=' symbol must be public variable names, while in the last expression all the variables are local (except those inside PUB).

Public variables can be specified by using the prefix '_', which does the same thing as PUB; thus, the expression:

B = PUB(A)

can be written as:

B = _A

Assignments work in the same way:

PSET A = B

can be written as:

_A = B
IGNORE 

Jump to the next input line (and ignore the rest of the program); it cannot appear inside an UDF.

CONSOLE expr

Print expr to stdout

CONSOLELN expr

Print expr to stdout and append CEOL

ERROR expr

Print expr to stderr

ERRORLN expr

Print expr to stderr and append EEOL

ABORT nExpr

Quit and set error level to nExpr.

PRINT expr

Write the value of the expression to the output file

PRINTLN expr

Write the value of the expression to the output file and append EOL

DEBUG 

Print out all public variable values in that moment; useful to determine why the program exhibits an unpredictable behaviour; if you want to check the value of a single variable, use CONSOLELN. Local variables (those inside an UDF), stacks, queues, bitmaps, arrays, sets, AVL trees are not printed: you must use CONSOLELN to view their values.

PAUSE [cExpr]

Print the specified expression (or, if omitted, a standard message requiring the user to press Enter) and suspend execution until the user presses the key, which is read from standard input.

Every method must appear on a line of its own; it the expression is very long, end the line with '\' and continue to the next line.

The methods:

PRINT PRINTLN CONSOLE CONSOLELN ERROR ERRORLN PAUSE SET PSET RETURN

support the composition of expr by writing one string after another:

PRINTLN "This " TOKEN(sentence, 2, " ") " a  test" 

is the same as:

PRINTLN STRCAT(STRCAT("This ", TOKEN(sentence, 2, " ")), " a test") 

In this way, expressions are more readable and the program is easier to write, because the user can avoid many unnecessary parenthesis.

This is the translation of control structures from C to Proteus:

Control structure

'C' code

Proteus code

While loop
while (test)
{
  ...
}
WHILE Test
  ...
LOOP
Conditional execution
if (test)
{
  ...
}
else
{
  ...
}
IF Test
  ...
ELSE
  ...
FI
Multiple cases
switch (exp)
{
  case val1_1:
  case val1_2:
    ...
    break;
  case val2:
    ...
  default:
    ...
    break;
}
SWITCH Exp
  ON Val1_1, Val1_2
    ...
  ONC Val2
    ...
  OTHER
    ...
OFF
For loop
for (x=s; x <= e; x += i)
{
  ...
}
FOR X = S TO E STEP I
  ...
NEXT
Do-while loop
do
{
  ...
} while (!test);
REPEAT
  ...
UNTIL Test
Conditional value
(test) ? (exp1) : (exp2)
IIF(test, exp1, exp2)

Proteus displays syntax errors by reporting the type of the error, the name of the file and the line where it appeared.

The following two code fragments are examples of wrong control structures:

WHILE LT(P, 10)
  IF EQ(P, 7)
    LOOP
  FI
  .. 

Error: LOOP cannot appear inside an IF when the corresponding WHILE is outside of the conditional control structure; LOOP is the ideal closing of the methods inside the WHILE loop; to jump to the test, use CONTINUE in this case.

IF LT(P, 10)
  WHILE LT(P, 5)
ELSE
  ..

Error: it is not possible to jump out of a WHILE loop; you cannot close conditional structures inside a WHILE if they were opened outside of it.

Start of page Next topic Previous topic Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell