﻿# DO File Statements

_Reviewed and reorganized June 2020_

**System Commands in DO Files**

Several system commands are of use mainly or only in the context a command or DO file. Those system commands are:

| **Command** | **Description** |
|------|------|
| [ECHO](echo.md) | Echoes <text> to screen. |
| [ELSE](else.md) | Conditional flow in command file. |
| [ENDIF](else.md) | 
| [IF](else.md) | 
| [EXIT](exit.md) | Exit command or DO file. |


**IF / ELSE / ENDIF Statements**

These statements are similar to their ASB counterparts. The following functions and expressions are supported by IF, with the same syntax as for ASB: 

| | | | | | | |
|------|------|------|------|------|------|------|
| ABS | CHR | FACT | LEFT | MID | SPACE | UCS |
| ACS | COS | FIX | LEN | RIGHT | SQR | VAL |
| ASC | DATN | INSTR | LOG | RND | STR |  |
| ASN | DEVICE | INT | LOG10 | SGN | TAN |  |
| ATN | EXP | LCS | LOOKUP | SIN | TIME |  |




The following operators are supported:

| **Relational Operators** | | **** | **Mathematical Operators** | 
|------|------|------|------|------|
| **Symbol** | **Meaning** | **** | **Symbol** | **Meaning** |
| = | Equal |  | \+ | Addition |
| <> | Not equal |  | \- | Subtraction |
| \# | Not equal |  | \* | Multiplication |
| \> | Greater than |  | / | Division |
| \>= | Greater than or equal |  | ^ | Raise to power |
| < | Less than |  | \*\* | Raise to power |
| <= | Less than or equal |  |  |  |




**Comments**

Note that unlike in ASB where many of the above functions could optionally have a \$ suffix (e.g. LEFT or LEFT\$), in DO files the \$ variation is not acceptable.

IF statements frequently operate on the [Special \$ Variables](special$variables.md), which see for further comments and examples.

**GOTO and EXIT Statements**

GOTO is similar to the ASB GOTO statement, except that it can only jump forward in the command file. The syntax of a label consists of a semicolon followed by the label name. See the label ";DONE" in the sample [MAIN.DO](commandfiles.md) file.

EXIT causes an immediate exit to the A-Shell command prompt, even if you are currently nested multiple levels deep in a command file.

**LOOKUP Statement**

The most useful of the above functions, LOOKUP, works slightly differently than the BASIC_plus_ equivalent. Instead of returning the file size, it always returns –1 if the file exists, else 0. The syntax is also different:

**LOOKUP <fspec>/Optional message if not found**

If the specified file is not found, the optional message (following the /, which is mandatory) is displayed and execution continues with the following line. Otherwise, the following line is skipped. Typically this is used with GOTO to create a conditional branch, as in the following:

LOOKUP \$0/\$0 does not exist\!

GOTO DONE                           ; (EXIT might also be appropriate here)

VUE \$0

;DONE

