Barcode sato international pte



Yüklə 401,84 Kb.
Pdf görüntüsü
səhifə9/13
tarix05.10.2018
ölçüsü401,84 Kb.
#72511
1   ...   5   6   7   8   9   10   11   12   13

Keyboard 

Programming Manual  

43 

SATO Europe 



 

Loop Statements 

Loop statements allow a program to execute one or more lines of code repetitively. 

The loop statements that TSKL supports include: 

 

DO…LOOP 


 

FOR…NEXT 

 

WHILE…WEND 



 

DO…[EXITDO]…LOOP 

Description 

Use a DO loop to execute a block of statements an indefinite number of times. There 

are  several  variations  of  DO…LOOP  statement,  but  each  evaluates  a  numeric 

condition to determine whether or not to continue execution. 

 

Syntax 


DO {WHILE | LOOP} 

 

Statements 



 

{EXITDO} 

LOOP 

 

Or 



DO 

 

Statements 



 

{EXITDO} 

LOOP {WHILE | LOOP} 

 

Or 



DO 

 

Statements 



 

{EXITDO} 

LOOP 

 



Programming Manual                                                      Keyboard

 

SATO Europe 



44

 

 



Remarks 

The total number of DO…LOOP statement in one program cannot exceed 40. 

The maximum number of IF…THEN…ELSE, FOR…NEXT, WHILE…WEND, and 

DO…LOOP statements available in one program is 40.  

 

Example 


A=1 

DO WHILE A<10 

A=A+1 

LOOP 


PRINT A 


Keyboard 

Programming Manual  

45 

SATO Europe 



 

FOR…[EXITFOR]…NEXT 

Description 

Executes a series of instructions by a specified number of times in a loop. 

(As opposed to DO …LOOP which executes until a condition is met) 

 

Syntax 



FOR variable= I TO J [STEP K] 

Statements 

NEXT variable 

 

Remarks 



I, J, K  are numeric expressions 

I:  


the initial value of the counter 

J:  


the final value of the counter 

K:  


The increment of the counter. If the K parameter is ignored, the default 

increment is 1. 

 

The maximum numbers of IF…THEN…ELSE, FOR…NEXT, WHILE…WEND, and 



DO…LOOP statements available in one program is 40. 

 

Example 



The following sample program prints out the sum of numbers between 1 and 10: 

SUM=0 


FOR I=1 TO 10 

SUM=SUM+I 

NEXT I 

PRINT SUM 




Programming Manual                                                      Keyboard

 

SATO Europe 



46

 

 



WHILE…WEND 

Description 

To execute a series of statements in a loop until the given condition is false. 

 

Syntax 



WHILE expression 

statements 

WEND 

 

Remarks 



If the expression is true the program will be executed until the WEND statement is 

encountered, then return to the WHILE statement to check again. After encountering a 

false condition, the program will branch to the statement following the WEND. 

 

The total numbers of WHILE…WEND statement in one program can not exceed 40. 



The maximum numbers of IF…THEN…ELSE, FOR…NEXT, WHILE…WEND, and 

DO…LOOP available in one program is up to 40.  

 

Example 


A=10 

WHILE A 


A=A-1 

PRINT “12345678” 

WEND 



Keyboard 

Programming Manual  

47 

SATO Europe 



 

GOTO 


Description 

Branches from the program to a specified block of statements. 

 

Syntax 


GOTO label 

 

Remarks 



Label is a tag to mark a specified position in the program. 

The Label name is limited to a maximum of 20 characters. 

The total number of GOTO statement in a program cannot exceed 200. 

 

Example 



INIT: 

SUM=0 


INDEX=1 

INPUT “S/N;”, SN$(INDEX) 

IF SN$=”” THEN GOTO INIT 



Programming Manual                                                      Keyboard

 

SATO Europe 



48

 

 



Program-Control Statements 

The program-control statements are the essence of any computer language because 

they govern the flow of program execution. Program-control statements may be 

separated into two categories: 

 

IF…THEN 


 

IF…THEN…ELSE 

 

IF…THEN…ELSE 



Description 

Use an IF…THEN block to execute one or more statements conditionally. You can use 

either a single-line syntax or multiple-line “block” syntax: 

 

Syntax 



IF condition THEN statement 

Notice that the single-line form of IF…THEN does not use an ENDIF statement. 

 

Or 


 

IF condition THEN 

  

Statements 



ENDIF 

 

Or 



 

IF condition THEN  

Statements  

ELSE 


 

Statements 

ENDIF 

 



Keyboard 

Programming Manual  

49 

SATO Europe 



 

Or 


 

IF condition1 THEN  

  

Statement block 1 



ELSEIF condition2 THEN 

  

Statement block 2 



ELSE 

 

Statement block n 



ENDIF 

 

Remarks 



If the result of the expression is nonzero, the statement following THEN will be 

executed. If the result of the expression is zero, and a statement following the ELSE is 

present, it will be executed. Otherwise the next line of statement is executed. 

If there are block of statements in IF…THEN …ELSE, ENDIF must be used at the end 

of the IF…THEN…ELSE statement. 

Limitations: 

The total number of IF…THEN…ELSE statements in a program can not exceed 40. 

The total numbers of IF…THEN…ELSE, FOR…NEXT, WHILE…WEND, and 

DO…LOOP in a program cannot exceed 40.  

 

Example 



IF A>0 THEN PRINT “TRUE” ELSE PRINT “FALSE” 

IF ANS=1 THEN 

CLS 

PRINT “Error!!!” 



INPUT ANS 

ENDIF 



Yüklə 401,84 Kb.

Dostları ilə paylaş:
1   ...   5   6   7   8   9   10   11   12   13




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə