2.2.1 for loop

It is the unconditional loop where the master cell value is variable according to loop count. Usually a break command is used to exit the loop.

The unconditional loop or endless loop is the simplest loop structure, for example:

 

A

B

C

1

=demo.query("select * from EMPLOYEE")

[]

 

2

for

=A1(A2)

 

3

 

if B2.STATE=="Texas"

 

4

 

 

>B1=B1|B2

5

 

if B1.len()==10

 

6

 

 

break

A2 executes an unconditional loop. B2 retrieves one employee record based on loop count in A2. The following code stores records of Texas employees in B1.After records of the first 10 Texas employees are retrieved, the loop is terminated in C6 with a break statement. Alternatively, a break C command, a form of break statement, can be used to exit the loop body that uses cell C as the master cell.

After execution, B1 contains the following result:

Note that when using the unconditional loop, you should make sure that the break statement can be executed properly, otherwise the program will loop endlessly.