# Program L ogic

Read（225） Label: program logic,

This chapter lists code examples about program logic, including Join data in a cellset program into a sequence, Implement switch/case-like structure, Get loop count, Proceed to/exit outer loop, Delete used variables to free memory, Pass multiple parameters to subroutine, Return multiple values by subroutine, Write multi-line comments, Write a long statement in multiple cells, and use macro in code.

## Join data in a program cellset into a sequence

 A B C D 1 1 2 3 4 2 =[A1:D1]

## Join data in a program cellset into a sequence

 A B C D 1 1 2 3 4 2 =[A1:D1]

## Implement switch/case -like structure

 A B 1 =80 2 if A1>=90 3 > A10="excellent" 4 else if A1>=80 5 > A10="good" 6 else if A1>=60 7 > A10="pass" 8 else 9 > A10="fail" 10 good

## Implement switch/case -like structure

 A B 1 =80 2 if A1>=90 3 > A10="excellent" 4 else if A1>=80 5 > A10="good" 6 else if A1>=60 7 > A10="pass" 8 else 9 > A10="fail" 10 good

## Get loop count

 A B C 1 for if #A1==10000 break

## Get loop count

 A B C 1 for if #A1==10000 break

## Proceed to /exit outer loop

 A B C D 1 for [3,2,1] 2 for [5,1,3] 3 if A1>B2 next A1 Proceed to the next loop 4 if A1== B2 break A1 Exit the outer loop

## Proceed to /exit outer loop

 A B C D 1 for [3,2,1] 2 for [5,1,3] 3 if A1>B2 next A1 Proceed to the next loop 4 if A1== B2 break A1 Exit the outer loop

## Delete used variables to free memory

 A 1 >var1=to(100) 2 =demo.query("select * from EMPLOYEE") 3 … 4 > var1=null,A2=null Delete variable var1 and the value of cell A2

## Delete used variables to free memory

 A 1 >var1=to(100) 2 =demo.query("select * from EMPLOYEE") 3 … 4 > var1=null,A2=null Delete variable var1 and the value of cell A2

## Pass multiple arguments to subroutine

 A B 1 func Multiple arguments are arranged in order 2 =A1 3 =B1 4 return B2+B3 5 =func(A1,11,21) 32

## Pass multiple arguments to subroutine

 A B 1 func Multiple arguments are arranged in order 2 =A1 3 =B1 4 return B2+B3 5 =func(A1,11,21) 32

## Return multiple values by subroutine

 A B 1 func 2 return [1,2,3,4] 3 4 =func(A1)

## Return multiple values by subroutine

 A B 1 func 2 return [1,2,3,4] 3 4 =func(A1)

## Write multi-line comments

 A B 1 //This is an example about… The words from line 1 to line 3 are all comments 2 1. Remark 1… 3 2. Remark 2… 4 =1+3

## Write multi-line comments

 A B 1 //This is an example about… The words from line 1 to line 3 are all comments 2 1. Remark 1… 3 2. Remark 2… 4 =1+3

## Write a long statement in multiple cells

 A B C D 1 68 2 ==if(A1>100:"excellent", A1>80:"good", A1>60:"pass", "fail")

## Write a long statement in multiple cells

 A B C D 1 68 2 ==if(A1>100:"excellent", A1>80:"good", A1>60:"pass", "fail")

## Use macro in code

 A B 1 [1,2,3,4] 2 func return A1.\${A2}() 3 func return A1.\${lower(A3)}() 4 =func(A2,"sum") Return A1.sum() 5 =func(A3,"Avg") Return A1.avg()

## Use macro in code

 A B 1 [1,2,3,4] 2 func return A1.\${A2}() 3 func return A1.\${lower(A3)}() 4 =func(A2,"sum") Return A1.sum() 5 =func(A3,"Avg") Return A1.avg()