Page images
PDF
EPUB

4570 LET L$="FAILED"

4580 IF T$<>U$ THEN 4620
4590 LET R$="FAILED"
4600 LET L$="FAILED"

4610 LET B$="F*"

4620 GOSUB 4900

4625 GOSUB 5000

4630 RETURN

4900 REM SUBROUTINE TO PRINT COMPARANDS FOR VARIABLE: VARIABLE 4910 PRINT V$; TAB(20); "V: ";W$; TAB(43); "V";

4920 RETURN

5000 REM SUBROUTINE TO PRINT RESULTS OF COMPARE

5010 PRINT TAB(47); A$; TAB(51); B$; TAB(55);L$

5020 RETURN

9000 END

PROGRAM FILE 18: THE IF-THEN STATEMENT WITH STRING OPERANDS. ANSI STANDARD 10.2, 10.4

SECTION 18.1: THE IF-THEN STATEMENT WITH STRING OPERANDS.

THIS SECTION TESTS THE COMPARISON OF STRING VARIABLES AND
CONSTANTS WITH A VARIETY OF VALUES. BOTH RELATIONSHIPS
(= AND <>) ARE TESTED FOR EACH PAIR OF VALUES. THE 'V' OR
'C' FOLLOWING THE COMPARAND VALUE INDICATES WHETHER IT IS
A VARIABLE OR A CONSTANT.

'T' OR 'F' IS PRINTED TO SHOW THE OUTCOME OF THE
COMPARISON. FOR INCORRECT COMPARES, AN '*' IS PRINTED
NEXT TO THE ERRONEOUS RESULT. WHEN DISPLAYING COMPARAND
VALUES, THE UNDERLINE CHARACTER, '', IS USED TO REPRESENT
THE SPACE CHARACTER (THUS A DISPLAYED 'ONE BLANK'
INDICATES AN INTERNAL VALUE OF 'ONE BLANK').

ALSO, THE NULL STRING (LENGTH OF ZERO) IS DENOTED BY THE
LABEL '(NULL STRING)'.

CHARACTER STRINGS SHOULD TEST EQUAL IF AND ONLY IF THE STRINGS ARE EQUAL IN LENGTH AND CONTAIN IDENTICAL SEQUENCES OF CHARACTERS.

[blocks in formation]
[blocks in formation]

10 PRINT "PROGRAM FILE 19: THE IF-THEN STATEMENT WITH NUMERIC OPERANDS" 20 PRINT " ANSI STANDARD 10.2, 10.4′′

30 PRINT

40 PRINT "SECTION 19.1: THE IF-THEN STATEMENT WITH NUMERIC OPERANDS." 50 PRINT

60 PRINT "THIS SECTION TESTS THE COMPARISON OF NUMERIC VARIABLES AND"

70 PRINT "CONSTANTS WITH A VARIETY OF NUMERIC VALUES. ALL RELATIONSHIPS"

80 PRINT "(=, <, >, <>, <=, >=) ARE TESTED FOR EACH PAIR OF VALUES."

85 PRINT "THE 'V' OR 'C' FOLLOWING THE COMPARAND VALUE INDICATES" 90 PRINT "WHETHER IT IS A VARIABLE OR A CONSTANT."

95 PRINT

100 PRINT "'T' OR 'F' IS PRINTED TO SHOW THE OUTCOME OF THE"
105 PRINT "COMPARISON. FOR INCORRECT COMPARES, AN '*' IS PRINTED"
110 PRINT "NEXT TO THE ERRONEOUS RESULT."

[merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][ocr errors][merged small]

***

280 LET A0=-3.14159E-26

290 GOSUB 3000

300 GOSUB 4000

310 LET A0=-3.14159

320 GOSUB 3000

330 GOSUB 4000

335 REM NOW DO CONSTANT: VARIABLE

340 LET BO=-98765500000

350 GOSUB 1000

360 GOSUB 4200

370 LET BO=-98765400000

380 GOSUB 2000

390 GOSUB 4200

400 LET BO=-3

410 GOSUB 3000

420 GOSUB 4200

430 LET BO=1.23456E-30

440 GOSUB 3000

450 GOSUB 4200

460 LET BO=456.789

470 GOSUB 3000

480 GOSUB 4200

490 REM TEST CONSTANT:CONSTANT

500 GOSUB 1000

510 IF -1.23456E-15=-.011E-13 THEN 530 520 LET A$=G$

530 IF -1.23456E-15 < .011E-13 THEN 550 540 LET B$=H$

550 IF -1.23456E-15 > -.011E-13 THEN 570 560 LET C$=1$

570 IF -1.23456E-15 <> -.011E-13 THEN 590 580 LET D$=J$

590 IF -1.23456E-15 <= .011E-13 THEN 610 600 LET E$=K$

610 IF -1.23456E-15 >= .011E-13 THEN 630

620 LET F$=L$

630 REM COMPARISONS FINISHED

640 PRINT "-1.23456E-15 C";TAB(18);": -.011E-13 C"; 650 GOSUB 5000

660 REM TEST VARIABLE: VARIABLE

670 LET A0=-0

680 LET BO=+0

690 GOSUB 2000

700 GOSUB 4400

710 LET A0=-3E36

720 LET B0=-3.001E36

730 GOSUB 3000

740 GOSUB 4400

750 LET A0=0E22

760 LET BO=1E-38

770 GOSUB 1000

780 GOSUB 4400

900 PRINT

910 PRINT "*** TEST ";R$;"

920 PRINT

[blocks in formation]

1010 LET A$="T*"

1020 LET B$="T" 1030 LET C$="T" 1040 LET D$="T" 1050 LET E$="T" 1060 LET F$="T" 1070 LET G$="F" 1080 LET H$="F*" 1090 LET I$="F" 1100 LET J$="F*" 1110 LET K$="F*"

1120 LET L$="F"

1140 RETURN

2000 REM SUBROUTINE TO INITIALIZE FOR CASE OF =

2010 LET A$="T"

2020 LET B$="T*" 2030 LET C$="T" 2040 LET D$="T*" 2050 LET E$="T" 2060 LET F$="T" 2070 LET G$="F*"

2080 LET H$="F"

2090 LET I$="F"

2100 LET J$="F"

2110 LET K$="F*"

2120 LET L$="F*"

2140 RETURN

3000 REM SUBROUTINE TO INITIALIZE FOR CASE OF >

3010 LET A$="T*"

3020 LET B$="T"

3030 LET C$="T"

3040 LET D$="T"

3050 LET E$="T*" 3060 LET F$="T"

3070 LET G$="F"

3080 LET H$="F"

3090 LET I$="F*"

3100 LET J$="F*"

3110 LET K$="F"

3120 LET L$="F*"

3140 RETURN

4000 REM SUBROUTINE TO TEST CONSTANT:VARIABLE

4010 IF +5.4321E-22 = AO THEN 4030

4020 LET A$=G$

4030 IF +5.4321E-22 <AO THEN 4050

4040 LET B$=H$

4050 IF +5.4321E-22 > AO THEN 4070

4060 LET C$=1$

4070 IF +5.4321E-22 <> AO THEN 4090 4080 LET D$=J$

4090 IF +5.4321E-22 <= AO THEN 4110

4100 LET E$=K$

4110 IF +5.4321E-22 >= AO THEN 4130

4120 LET F$=L$

4130 REM COMPARISONS FINISHED

4140 PRINT "+5.4321E-22 C";TAB(18);": ";A0;"V"; 4150 GOSUB 5000

4160 RETURN

4200 REM SUBROUTINE TO TEST VARIABLE:CONSTANT

4210 IF BO = -98765400000 THEN 4230

4220 LET A$=G$

4230 IF BO < -98765400000 THEN 4250 4240 LET B$=H$

4250 IF BO > -98765400000 THEN 4270

4260 LET C$=1$

4270 IF BO <> -98765400000 THEN 4290 4280 LET D$=J$

4290 IF BO <= -98765400000 THEN 4310

4300 LET E$=K$

4310 IF BO >= -98765400000 THEN 4330

4320 LET F$=L$

4330 REM COMPARISONS FINISHED

4340 PRINT BO; "V";TAB(18);": -98765400000 C"; 4350 GOSUB 5000

4360 RETURN

4400 REM SUBROUTINE TO TEST VARIABLE:VARIABLE

4410 IF AO BO THEN 4430

4420 LET A$=G$

4430 IF AO < BO THEN 4450

4440 LET B$=H$

4450 IF AO > BO THEN 4470

4460 LET C$=I$

4470 IF AO <> BO THEN 4490

4480 LET D$=J$

4490 IF AO <= BO THEN 4510

4500 LET E$=K$

4510 IF AO >= BO THEN 4530

4520 LET F$=L$

4530 REM COMPARISONS FINISHED

4540 PRINT AO;"V"; TAB(18);": ";BO; "V";

4550 GOSUB 5000

4560 RETURN

5000 REM SUBROUTINE TO CHECK OUT AND PRINT RESULTS OF COMPARE

[merged small][merged small][ocr errors][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small][merged small]
« PreviousContinue »