You can now find a list of all the native pert functions, for math, drawing, etc, on a separate page.
General Pert C
comments
Both C and C++ style comments are supported.
// one-line comment
/* multi line
comments are nice */
types
Pert supports the following types: bool, char, int, float, void (for functions only), bool arrays, char arrays, int arrays, and float arrays.
Note: it is best to declare arrays as globals (rather than within a function) for optimal efficiency. Arrays can be declared with sizes that reference integer variables...just make sure those variables are assigned values first.
int a = 10;
float d,e,f[10];
bool bList[20];
char g, h;
int iList[a];
expressions
Expressions should behave like regular C expressions. For boolean expressions, sometimes parentheses are necessary.
a = 4;
f[2] = 3.0+1.3;
bList[0] = (a<3);
functions
Function declarations are optional. Arrays cannot be arguments of functions, nor can they be returned.
float square(float d)
{
return d*d;
}
int avg( int a, int b )
{
return (a+b)/2;
}
if
If statements should behave just like regular C if statements, including having optional else clauses.
As with all blocks, curly braces can be left out for a one-statement block.
if ( d < e ) {
// code goes here
}
if ( bList[3] )
// do something here
else
// or something here
while
While statements should behave just like regular C while statements. Use the "break;" command to exit a while loop. While loops which go on for too long (like over a million times) will be stopped as a measure against infinite loops.
while(a<10) {
a = a + 2;
}
while(true)
{
break;
}
for
For statements should behave just like regular C For statements. Use the "break;" command to exit a for loop. For loops which go on for too long (like over a million times) will be stopped as a measure against infinite loops.
for(a=0; a<10; a++)
{
d = 5.4*a;
}
for(a=0; a<10; a++)
{
if (a==3)
break;
}
return
Return is used to return a value from a function. Return can be used at any point within a function, and it will instantly leave the function, without executing any more function code. Returned value types should match the type of the function.
return 7;
return 14+3.2;
last updated 3/31/01 by jarfish