for x

Read(1602) Label: execute a loop,

Description:

Start a loop.

Syntax:

for  x

Note:

The statement starts a loop executing the code block.

Parameter:

x

A sequence, an integer, or a logic expression. Loop through the code block against x or to(x), or if x is true. If x is empty, then the loop will be endless.

When the parameter is a table sequence, you can use a loop function symbol in the for x code block.

Example:

x is an integer:

 

A

B

 

1

 

 

Save the cumulative total 55 in A1.

2

for 10

 

 

3

 

>A1=A1+A2

Add up integers from 1 to 10.

 

 

x is empty:

 

A

B

C

 

1

=0

 

 

5050.

2

for

 

 

Loop will be endless if x is empty. When the loop count reaches 100, then break the loop.

3

 

>A1=A1+#A2

 

 

4

 

if #A2==100

break

 

 

x is a Boolean expression:

 

A

B

 

1

=15

 

 

2

for A1>10

 

If A1 >10, then start a loop through the code block; otherwise, quit the loop.

3

 

>B1=B1+#A2

4

 

>A1=A1-1

 

 

 

x is a sequence:

 

A

B

 

1

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

0

Get the oldest age among all Texas employees in B1 after the loop is over.

2

=A1.select(STATE=="Texas")

 

 

3

for A2

=age(A3.BIRTHDAY)

A3 performs loop over each Texas employee while computing their age.

4

 

>B1=max(B1,B3)

The oldest age is stored in B1.

 

Use a loop function symbol when parameter x is a table sequence:

 

A

B

 

1

=to(10)

 

 

2

for A1

 

A2 executes the loop operation to compute the cumulative sum of members of A1’s sequence and return 55, which is written to cell B1. ~ in B3 is a loop function symbol representing the current member value of the cell A,

3

 

>B1=B1+~