# readnext statement

The readnext statement retrieves the
next item-ID from an active list and assigns it to a specified variable.

## Syntax

```
 readnext ID.var{,value.count}{from select.var} [then|else statement.block]
```

## Parameter(s)

| value.count | Indicates the position of the multivalue within an attribute. This is a by-product of an exploded sort, executed prior to the execution of the program. This allows multivalues to be retrieved in exploded sort sequence. If the list is not exploded, the value count value is always 1. |
| --- | --- |
| select.var | If select.var is not specified, the default primary or secondary select variable is used. The secondary specification uses the active secondary list. |

## Description

A list must be active before the readnext statement occurs. The list can be
 generated within the program or the list can be passed into the program from an external
 process, such as TCL or a Proc, that invokes a list-producing command immediately before
 running this program.

The else condition is executed when there are no more items
in the list.

Tip: Another select clears the primary and secondary lists.

The select and readnext statements both consume an external
 list if one is available. As a result, system(11) always returns 0
 after one of these commands.

 For example:

```

 execute "select bp sampling 5"
 print system(11)
 select
 print system(11)
```
This prints 5, then 0. The external list is consumed by a BASIC variable, and is then only
 available from FlashBASIC or BASIC.

When using an external list, it is necessary to readnext all items in that
 list until the readnext statement actually fails. At this point, the
 list is reset and it searches again for a new external list.

## Example(s)

**Example 1**

The readnext statement retrieves the next itemID from an active list, but does
 not implicitly address the file. The file to be accessed must be opened before an
 attempt to use the itemID in a read statement can be made.

```

 open ’customer’ to customer.file else stop 201,’customer’
 execute ’sselect customer with balance.due by name’
 loop
 readnext itemID else stop
 read item from customer.file,itemID then
 print ’the name is ’:item<1>
 end
 repeat
```

 **Example 2**

This example displays each itemID.

```

 execute "select md (s"
 loop readnext ID else stop
 print ID
 repeat
```

## See also

- [Active list](https://d3codex.com/definitions/active-list/)
- [begin work statement](https://d3codex.com/pickbasic-flashbasic/begin-work-statement/)
- [by-exp modifier](https://d3codex.com/access/by-exp-modifier/)
- [by-exp-dsnd modifier](https://d3codex.com/access/by-exp-dsnd-modifier/)
- [execute statement (UNIX)](https://d3codex.com/pickbasic-flashbasic/execute-statement-unix/)
- [clearfile statement](https://d3codex.com/pickbasic-flashbasic/clearfile-statement/)
- [fl command](https://d3codex.com/tcl/fl-command/)
- [get-list command](https://d3codex.com/tcl/get-list-command/)
- [if statement](https://d3codex.com/pickbasic-flashbasic/if-statement/)
- [loop statement](https://d3codex.com/pickbasic-flashbasic/loop-statement/)
- [open statement](https://d3codex.com/pickbasic-flashbasic/open-statement/)
- [Secondary list](https://d3codex.com/definitions/secondary-list/)
- [select command](https://d3codex.com/access/select-command/)
- [clearselect statement](https://d3codex.com/pickbasic-flashbasic/clearselect-statement/)
- [sselect command](https://d3codex.com/access/sselect-command/)
- [statement blocks](https://d3codex.com/pickbasic-flashbasic/statement-blocks/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)
- [system() function](https://d3codex.com/pickbasic-flashbasic/system-function/)
- [then/else statement blocks](https://d3codex.com/pickbasic-flashbasic/then-else-statement-blocks/)
- [u21a3 user exit](https://d3codex.com/pickbasic-flashbasic/u21a3-user-exit/)

---
Source: https://d3codex.com/pickbasic-flashbasic/readnext-statement/ - part of the D3Codex reference.
