# ON...GOTO Conditional Transfer of Control

> Source: https://manual.pvxplus.com/directives/on-goto

## Format

**ON** *num **GOTO** stmtref,stmtref,...*  
  
***Where***:

|  |  |
| --- | --- |
| *num* | Value determines the location to which to transfer. Numeric expression. Integer range -32768 to +32767. |
| *stmtref* | Program line number or statement label to which to transfer control. |

## Description

Use the **ON ... GOTO** directive to transfer control to one of the statements listed based on the value you provide:

|  |  |  |
| --- | --- | --- |
|  | *num* \<=0 | Control is transferred to the first statement specified. |
|  | *num* =1 | Control is passed to the second statement number specified. |
|  | *num* =2 | Control is passed to the third. |
|  | *num* =3… *nnn* | Control is passed sequentially. |

If *num* is greater than the number of *stmtref* supplied, the last *stmtref* is assumed.

## See Also

[GOTO Transfer Within Program](https://manual.pvxplus.com/directives/goto)

## Example

```
0020 on X goto 0100,0200,0300,0400,0500
```

|  |  |  |
| --- | --- | --- |
|  | **ON...** | **GOTO** |
|  | X \<= 0 | Transfers to 0100 |
|  | X = 1 | Transfers to 0200 |
|  | X = 2 | Transfers to 0300 |
|  | X = 3 | Transfers to 0400 |
|  | X >= 4 | Transfers to 0500 |
