M!INTOUCH® 4GL Y

INTOUCH® 4GL
A Guide to the INTOUCH Language

A
Previous page... 6Table of Contents
;

11.5 IF/THEN ... END IF



FORMAT:



5        IF cond_expr THEN statement [ELSE statement]                  or          IF cond_expr1 THEN             ---             ---  block of code             ---          [ELSEIF cond_expr2 THEN             ---             ---  block of code             ---   ...]         [ELSE             ---             ---  block of code             ---      ]         END IF 




EXAMPLE:



1        10  INPUT PROMPT 'Enter your age: ': age 2            INPUT PROMPT 'Enter your sex: ': sex$ F        20  IF  UCASE$(sex$[1:1]) = 'M'  THEN  GOTO  done  ELSE PRINT "        30  IF  age < 20  THEN +              PRINT 'Please go to line A.' 8            ELSEIF  age > 19  AND  age < 40  THEN +              PRINT 'Please go to line B.'             ELSE +              PRINT 'Please go to line C.'             END IF         40  done: END          RNH         Enter your age: 25         Enter your sex: female          Please go to line B. 


PURPOSE:





AUse the IF construct when you want to execute a statement 1or block of code only under specific conditions. 



DESCRIPTION:





?The simplest form of the IF construct is a one-line statement: 

$        IF cond_expr THEN statement 


Fcond_expr is a conditional expression. INTOUCH evaluates this :expression as either TRUE (1) or FALSE (0). GIf the condition is TRUE, INTOUCH executes the statement following the ;THEN. If the condition is FALSE, INTOUCH skips the 8statement following the THEN and goes to the next line. 

FIn the example program, when INTOUCH executes the first IF statement, Jit evaluates the conditional expression, SEX$[1:1] = 'M'. IF the user is J'Male' the condition is TRUE and INTOUCH executes the statement following the THEN and jumps to DONE:. 

CIF can be used to execute a block of code. The IF block construct looks like this: 

        IF cond_expr THEN               ---       !              ---  block of code               ---         END IF 


JIf the conditional expression is TRUE, INTOUCH executes the block of code <beginning on the next line. END IF marks the end of Fthis block of code. If the expression is FALSE, INTOUCH skips to the statement following the END IF. 



8

11.5.1 ELSE Option





?The ELSE option executes a statement if the conditional Jexpression is FALSE. The format of the IF statement with the ELSE option is: 

3        IF cond_expr THEN statement ELSE statement 


EWhen INTOUCH executes the IF statement, it evaluates the conditional Iexpression. If the expression is TRUE, the statement following the THEN Jis executed. If the expression is FALSE, the ELSE statement is executed. $(Please refer to previous example.) 

        RNH         Enter your age: 19         Enter your sex: Female          Please go to line A. 


DIn the above program, when INTOUCH executes the first IF statement, Iit evaluates the expression, SEX$[1:1] = 'M'. Since the user is Female, Gthe expression is FALSE, so INTOUCH skips the THEN clause and jumps to Hthe ELSE clause. INTOUCH executes the code between the ELSE clause and the END IF. 

JThe ELSE option can be used to execute a block of code if the conditional Mexpression is FALSE. The IF construct with the ELSE option looks like this: 

        IF cond_expr THEN               --- !              ---  block of code               --- 
        ELSE               --- !              ---  block of code               ---         END IF 


JIf the conditional expression is TRUE, INTOUCH executes the block of code Ebetween the IF and the ELSE statements. If the expression is FALSE, DINTOUCH executes the block of code between the ELSE and the END IF. 

1        10  INPUT PROMPT 'Enter your age: ': age 2            INPUT PROMPT 'Enter your sex: ': sex$ <        20  IF  UCASE$(sex$[1:1]) = 'M'  THEN  GOTO the_end             PRINT "        30  IF  age < 40  THEN +              PRINT 'Please go to line A.'             ELSE +              PRINT 'Please go to line B.'             END IF         40  the_end: END          RNH         Enter your age: 45         Enter your sex: female          Please go to line B. 


HIn the above program, when INTOUCH executes the second IF statement, it Nchecks to see if "AGE < 40". Since AGE is not less than 40, the condition Kis FALSE. INTOUCH skips the code following the THEN and jumps to the ELSE >clause. INTOUCH executes the code following the ELSE clause. 



:

11.5.2 ELSEIF Option








@The ELSEIF option sets up a new condition to check. The 6format of the IF construct with the ELSEIF option is: 

        IF cond_expr1 THEN               --- !              ---  block of code               ---         ELSEIF cond_expr2 THEN               --- !              ---  block of code               ---            
        ELSE B              ---                                                 !              ---  block of code                ---                       END IF 


KELSEIF establishes a new condition. INTOUCH evaluates this condition. If Kthe condition is TRUE (1), INTOUCH executes the code following the ELSEIF. JIf the condition is FALSE (0), INTOUCH jumps to the next clause in the IF construct. 

1        10  INPUT PROMPT 'Enter your age: ': age 2            INPUT PROMPT 'Enter your sex: ': sex$ G        20  IF  UCASE$(sex$[1:1]) = 'M'  THEN  GOTO the_end ELSE PRINT "        30  IF  age < 20  THEN +              PRINT 'Please go to line A.' 8            ELSEIF  age > 19  AND  age < 40  THEN +              PRINT 'Please go to line B.'             ELSE +              PRINT 'Please go to line C.'             END IF         40  the_end: END          RNH         Enter your age: 25         Enter your sex: Female          Please go to line B. 


GIn the above program when INTOUCH executes the second IF statement, it Jchecks to see if "AGE < 20". Since AGE is not less than 20, the first Jcondition is FALSE. INTOUCH skips the code following the THEN and checks Pthe condition set up by the ELSEIF. Since "AGE > 19" and "AGE < 40", the Esecond condition is TRUE and INTOUCH executes the code following the FELSEIF and prints 'Please go to line B.', then exits the conditional. 



?

11.6 SELECT CASE/END SELECT



FORMAT:



        SELECT CASE main_expr          CASE expr1[, expr2,...]             ---             ---  block of code             --- !        [CASE expr3[, expr4,...]             ---             ---  block of code              ---            ...] =        [CASE IS {numeric operator | boolean operator} expr5             ---             ---  block of code              ---            ...]         [CASE ELSE             ---             ---  block of code              ---            ...]         END SELECT 


EXAMPLE:



        10  DO 3              INPUT 'Your income per year': income 2              IF  _BACK  OR  _EXIT  THEN  EXIT DO !        20    SELECT CASE income               CASE 0 #                PRINT 'No income?'               CASE IS < 0 =                PRINT 'A negative income?  You are in debt!'               CASE IS > 0 +                PRINT 'A positive income.'               END SELECT             LOOP         30  END          RNH          Your income per year? 0         No income? %        Your income per year? -15000 ,        A negative income? You are in debt! $        Your income per year? 30000         A positive income. #        Your income per year? exit 


PURPOSE:





JSometimes you need to compare one main expression with several values and @execute a different block of code for each possible match. Use ASELECT CASE to check a set of conditions and execute code depending on the results. 



DESCRIPTION:





BThe SELECT CASE statement begins the construct and gives the main Dexpression (main_expr). In the example, the main expression =is INCOME. The CASE statements are compared with the Bmain expression. The first CASE expression (expr1) is 0. IFollowing this CASE is a block of code. If INCOME = 0 the block of code following CASE 0 is executed. 




E

11.6.1 CASE expr, expr, expr...



;Each CASE statement can include several expressions Iseparated by commas. INTOUCH compares each of the expressions in a CASE Bstatement. If any of them match, the block of code following the CASE is executed. 

        10  DO 7              INPUT 'Procedure (add, del, exit)': pro$ '              IF  _EXIT  THEN  EXIT DO "              pro$ = UCASE$(pro$)         20    SELECT CASE pro$               CASE 'ADD' "                PRINT 'Adding...' #              CASE 'DEL', 'DELETE' $                PRINT 'Deleting...'               END SELECT             LOOP         30  END          RNH (        Procedure (add, del, exit)? ADD         Adding... (        Procedure (add, del, exit)? DEL         Deleting... )        Procedure (add, del, exit)? EXIT 


>The following example illustrates how to check for a range of values: 

        10  a = 5             SELECT CASE a #              CASE 1 : PRINT 'one' *              CASE 2 to 6 : PRINT 'range' '              CASE ELSE : PRINT 'else'             END SELECT         20  b$ = 'c'             SELECT CASE b$ #              CASE 'a' : PRINT 'a' .              CASE 'b' to 'e' : PRINT 'range' '              CASE ELSE : PRINT 'else'             END SELECT         30  END          RNH         range         range 
=

11.6.2 CASE ELSE Option



=The CASE ELSE option executes a block of code only if Knone of the CASE expressions match. SELECT CASE with the CASE ELSE option looks like this: 

        SELECT CASE main expr         [CASE expr1, expr2...             ---             ---  block of code              ---            ...] <        [CASE IS {numeric operator| boolean operator} expr3             ---             ---  block of code              ---            ...]         CASE ELSE             ---             ---  block of code             ---         END SELECT 


DCASE ELSE must follow the last CASE statement. If none of the CASE @expressions match, INTOUCH executes the block of code following the CASE ELSE statement. 

        10  DO 8              INPUT 'Procedure (add, del, exit)' : pro$ '              IF  _EXIT  THEN  EXIT DO #              pro$ = UCASE$(pro$)          20    SELECT CASE pro$               CASE 'ADD' "                PRINT 'Adding...' #              CASE 'DEL', 'DELETE' $                PRINT 'Deleting...'               CASE ELSE E                MESSAGE ERROR: 'Procedure must be: add, del or exit'                 REPEAT DO               END SELECT             LOOP         30  END          RNH (        Procedure (add, del, exit)? add         Adding... (        Procedure (add, del, exit)? del         Deleting... ,        Procedure (add, del, exit)? funny    <                        Procedure must be add, del, or exit  )        Procedure (add, del, exit)? EXIT 
;

11.6.3 CASE IS Option



<CASE IS lets you form a conditional expression to be Kchecked against the main expression. The format of the CASE IS option is: 

+        CASE IS {relational operator} expr 


BWhen the CASE IS statement executes, INTOUCH compares expr 7to the main_expr using the relational operator. 

        10  DO 3              INPUT 'Your income per year': income 2              IF  _BACK  OR  _EXIT  THEN  EXIT DO !        20    SELECT CASE income               CASE 0 #                PRINT 'No income?'               CASE IS < 0 =                PRINT 'A negative income?  You are in debt!'               CASE IS > 0 +                PRINT 'A positive income.'               END SELECT             LOOP         30  END          RNH %        Your income per year? -15000 -        A negative income?  You are in debt!          Your income per year? 0         No income? $        Your income per year? 25000         A positive income. #        Your income per year? exit 
7

11.7 CHAIN Programs



FORMAT:



        CHAIN 'file_spec' 


EXAMPLE:



8        10  LINE INPUT 'Your name (last, first)': name$ 7            OPEN #1: NAME 'storage.tmp', ACCESS OUTPUT             PRINT #1: name$             CLOSE #1 :        20  INPUT 'Add to CLIENT structure (Y/N)': reply$ 0            IF  reply$ = 'Y'  THEN  CHAIN 'ADD'         30  END          RNH -        Your name (last, first)? Woods, Jack )        Add to CLIENT structure (Y/N)? N 


DESCRIPTION:





<CHAIN exits the current program and runs the program specified. 

Hfile_spec is the specification for the program being chained to. KThe file specification can be any string expression. INTOUCH searches for Lthe file specified. INTOUCH exits the current program and runs the program >named. Control does not return to the current program Hwhen the chained program is finished. If INTOUCH cannot find the file, Hor if the file is not an executable program, an exception is generated. 

/When INTOUCH executes the CHAIN statement, it: 




N

11.8 Pass Commands to the Operating System



G

11.8.1 PASS [NOWAIT: | NORETURN:]



FORMAT:



,        PASS [NOWAIT: | NORETURN:] str_expr 


EXAMPLE:



7        10  INPUT 'What would you like to show': info$ !        20  PASS 'SHOW ' + info$         30  END          RNH ,        What would you like to show? user t  @              VAX/VMS User Processes at  9-MAY-1995 10:22:29.87 @            Total number of users = 1,  number of processes = 1  <         Username  Node     Interactive  Subprocess   Batch '         TESTER       TTI            1 


PURPOSE:





;Use PASS to perform system commands without leaving .the INTOUCH environment or exiting a program. 



DESCRIPTION:





DPASS passes the specified string expression to the operating system Ccommand interpreter. Generally, it passes the string to DCL. The Goperating system will respond to the string as it would if you entered Fit at the DCL $ prompt. When the system finishes, control returns to the INTOUCH program. 

?When you use the NOWAIT option with PASS, the operating Lsystem executes the passed command and immediately returns to INTOUCH 2without waiting for the passed command to finish. 



EXAMPLE:



'        10  PASS NOWAIT: 'show user t'         20  END          INTOUCH         RNH          INTOUCH @              VAX/VMS User Processes at  9-MAY-1995 10:23:19.87 @            Total number of users = 1,  number of processes = 1  <         Username  Node     Interactive  Subprocess   Batch '         TESTER       TTI            1          end          INTOUCH




;The PASS NORETURN statement passes a command to the 1operating system but does not return to INTOUCH. 



EXAMPLE:



         10  PRINT 'B E F O R E'         20  DELAY 2 )        30  PASS NORETURN: 'show user t'         40  END          RNH         B E F O R E  @              VAX/VMS User Processes at  9-MAY-1995 01:43:14.36 @            Total number of users = 1,  number of processes = 1  <         Username  Node     Interactive  Subprocess   Batch &         TESTER      TTI            1 
        $ 
2

11.9 Branching



?Branching means jumping from one part of a program to another. EBranching is especially useful when combined with conditionals. For Eexample, you can ask the user to choose a procedure. You can branch Eto different subroutines in your program, depending on the procedure chosen. 

?There are several statements used for branching: GOTO, GOSUB, EDISPATCH, ON GOTO, and ON GOSUB. GOTO causes INTOUCH to jump to the Especified location and continue normal program execution from there. 

FGOSUB and DISPATCH execute routines and subroutines. Subroutines are Jblocks of code that INTOUCH branches to, executes, and then returns from. 

DGOTO, GOSUB, and DISPATCH cause unconditional branching. When they <are executed, INTOUCH jumps to the statement specified. To @conditionally branch, combine these statements with conditional =statements. Two other constructs, ON GOTO and ON GOSUB, are Econditional. Both ON GOTO and ON GOSUB branch to one of a number of Aplaces in the program depending an integer expression. When the AON GOSUB construct is used, INTOUCH will return to the statement Cfollowing the ON GOSUB when the subroutine has finished executing. 

F

11.9.1 Branching and Code Blocks



DCertain constructs (such as GOSUB) include a block of code which is Fexecuted within the construct. You can transfer control within these 8code blocks and out of these code blocks. For example: 

,                           10  DIM name$(4) .                           20  FOR i = 1 TO 4 E                                 INPUT 'Your name, please': name$(i) N       branches within block --    IF  name$(i) <> ''  THEN  GOTO hello =       branches out of block --    IF  _EXIT  THEN  EXIT FOR (                                 hello: 2                                   PRINT 'Hello!' &                           30  NEXT i 0                           40  PRINT 'Finished' *                           50  END        
/

11.10 GOTO



FORMAT:



        GOTO target 


EXAMPLE:



        10  start: %            INPUT 'Your Name': name$ *            IF  _EXIT  THEN  GOTO the_end #            PRINT 'Hello, '; name$             GOTO start         20 the_end: END          RNH         Your Name? Tony         Hello, Tony         Your Name? Betty         Hello, Betty         Your Name? exit 


PURPOSE:





<Use GOTO when you want to jump from one part of your program to another. 



DESCRIPTION:





Atarget is the line to which control is being transferred. -target can be a label or line number. 


,

Note

FIt is recommended that you branch to labels rather than line numbers. CShould the line numbers change, the change would have no effect on your branching code. 



IWhen INTOUCH executes a GOTO statement, it branches to the target Fline specified. Any code between the GOTO and the target line Lis skipped. INTOUCH continues normal program execution at the target line. 



A

11.10.1 ON...GOTO...[ELSE]



FORMAT:



A        ON int_expr GOTO target1 [, target2...] [ELSE statement] 


EXAMPLE:



?        10  ask: INPUT 'Procedure (1=add, 2=del, 3=exit)': pro '        20  ON pro GOTO add, del, done             add:                PRINT 'Adding...'               GOTO ask             del: "              PRINT 'Deleting...'               GOTO ask         30  done: END          RNH ,        Procedure (1=add, 2=del, 3=exit)? 2         Deleting... ,        Procedure (1=add, 2=del, 3=exit)? 1         Adding... ,        Procedure (1=add, 2=del, 3=exit)? 3 


PURPOSE:





FSometimes you want to jump to one of several places in your program. ;ON...GOTO lets you jump to one of several locations %depending on a condition you set up. 



DESCRIPTION:





Aint_expr is the integer expression or condition to check. Btarget1, target2 ... is a list of places to jump to. Each &target can be a label or line number. 

FON..GOTO branches to one of several targets depending on the value of =an integer expression. The simplest version of ON..GOTO is, 

-        ON int_expr GOTO target1, target2... 


Fint_expr is an integer expression whose value determines where Gcontrol is transferred. When INTOUCH executes the ON GOTO statement, Jit evaluates the integer expression. If the value is 1, INTOUCH branches Ito the first target in the list. If the value is 2, INTOUCH branches to the second target, and so on. 

KIf the expression does not evaluate to an integer, INTOUCH rounds it. The Gvalue must be from 1 to the number of targets (unless there is an ELSE Iclause). For example, if there are five targets, the integer value must be from 1 to 5. 

GIf the value is less than 1 or greater than the number of targets, and :there is no ELSE clause, INTOUCH generates an exception. 

'Targets can be labels or line numbers. 

IINTOUCH supports 128 targets for ON...GOTO. More targets than 128 gives 'an "expression too complex" exception. 



>

11.10.1.1 ELSE Option



;The ELSE option executes a statement if the integer Gexpression does not find a target. ON GOTO with the ELSE option looks like this: 

?        ON int_expr GOTO target1 [, target2...] ELSE statement 


FELSE must be followed by a statement. The ELSE is executed if Hthe integer value exceeds the number of targets in the list, is zero or is negative. 

        10  start: :            INPUT 'Procedure (1=add, 2=del, 3=exit)': pro D        20  ON pro GOTO add, del, done ELSE PRINT 'Enter 1, 2 or 3'             GOTO start             add:                PRINT 'Adding...'               GOTO start             del: "              PRINT 'Deleting...'               GOTO start         30  done:             PRINT 'Finished'             END          RNH -        Procedure (1=add, 2=del, 3=exit)? -2         Enter 1, 2 or 3 ,        Procedure (1=add, 2=del, 3=exit)? 1         Adding... ,        Procedure (1=add, 2=del, 3=exit)? 3         Finished 
7

11.11 GOSUB/RETURN

4

11.11.1 GOSUB



FORMAT:



        GOSUB target                .                .                .         target             ---             ---  block of code             ---         RETURN 


EXAMPLE:



        10  GOSUB get_input #        20  PRINT 'Hello, '; name$             GOTO exit         30  get_input: +            INPUT 'Enter your name': name$ "            name$ = UCASE$(name$)             RETURN         40  exit:             PRINT 'Finished'         50  END          RNH          Enter your name? Julian         Hello, JULIAN         Finished 


PURPOSE:





>Use GOSUB to jump to another location in your program, Iexecute the code at that location and then return to the place you left. 



DESCRIPTION:





LGOSUB transfers control to a subroutine. The subroutine is a block of code. NINTOUCH executes the code, then returns to the statement following the GOSUB. AThe target can be a label, a ROUTINE statement or a line number. 


,

Note

FIt is recommended that you branch to labels rather than line numbers. CShould the line numbers change, the change would have no effect on your branching code. 



?If the target in the GOSUB statement does not exist, an Gexception is generated. RETURN or END ROUTINE ends the subroutine and 8transfers control to the statement following the GOSUB. 

-You can nest 64 GOSUBs up to 64 levels deep. 






,

Note

CIf your label or routine name contains an underscore (_) character B(e.g. ask_name, do_add), you do NOT need to use the word "GOSUB". >Under these conditions, the "GOSUB" is implied. For example: 9using ASK_NAME would be the same as using GOSUB ASK_NAME 





4


Next page... | 6Table of Contents