Code Block

Read(3306) Label: code block,

The master cell of a code block is its starting cell. Now let’s look at which cells a code block can cover.

A code block covers the row holding the master cell and the following one or more consecutive rows, if any, where the cells in both the master cell column and the column(s), if any, to the left are blank. This indicates the code block can extend until a row where any cell in the master cell column or a column to the left is non-blank appears. From that row on, the cellset is outside this code block.

 

A

B

C

D

1

 

 

 

 

2

 

>Code begin

 

 

3

 

 

 

 

4

 

 

 

 

5

 

 

 

 

6

Not null

Not null

 

 

In the above cellset, suppose B2 is a code block’s master cell. The cells in the green area are blank, thus rows from the second to the fifth constitute the master cell’s code block. The code block ends before row 6 since neither A6 nor B6 in the red area is blank, no matter it is the code cell, calculation cell, executable cell, constant cell or comment cell. 

A code block can not only hold a single statement, it can also perform a loop procedure or a branch instruction by putting the correponding statement in the master cell. For example:

 

A

B

C

1

=demo.query("select NAME as CITY, STATEID as STATE from CITIES")

[]

 

2

for A1

=demo.query("select * from STATES where STATEID=?",A2.STATE)

 

3

 

if left(B2.ABBR,1)=="N"

>A2.STATE=B2.NAME

4

 

 

>B1=B1|A2

The above code contains code blocks. The code block with A2 being the master cell executes a loop and the one with B3 being the master cell executes an instruction of judgment. B1 also gets the cities whose home states’ abbreviations begin with "N".

However, the code blocks under discussion are not the cases where a statement is used to introduce various instructions, but those cases where a statement is written in multiple cells according to sequential cells rule and thus should be executed as a whole. The rule allows the a statement written in a calculation cell or an executable cell to automatically move on to the next cell when certain characters, including ",", ";" and "(", are entered until no such characters appear or the statement reaches the end.

 

If the string in a cell starts with //, the code block with this cell being the master cell holds comments and it is thus called as a comment block. esProc will skip the whole comment block when encountering it. For example:

 

A

B

1

//comment

1.note...

2

 

2.note...

3

 

3.note...

4

 

=1+1

5

=1+1

 

Within the code block whose master cell is A1, all cells, including B4 of course, are naturally treated as comment cells, without the need of being marked with a slash / in the front as in a comment cell. The non-blank A5 marks the end of the code block, and the expression in A5 will be parsed and computed normally.

Different from a calculation block, an assignment block and an executable block, a comment block contains no expression for execution, so it doesn’t need the sequential cells rule.