Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc.

Similar documents
Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

Chapter 1 INTRODUCTION. SYS-ED/ Computer Education Techniques, Inc.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Add Subtract Multiply Divide

Statements and Operators

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc.

Repetition Structures

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

C-LANGUAGE CURRICULAM

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

REXX programming for the z/os programmer

Unit 3. Operators. School of Science and Technology INTRODUCTION

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

3 The L oop Control Structure

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Quick Reference Guide

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

Lecture 7 Tao Wang 1

Quick Reference Guide

Flow Control. CSC215 Lecture

Unit 6 - Software Design and Development LESSON 3 KEY FEATURES

BASIC ELEMENTS OF A COMPUTER PROGRAM

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Special Section: Building Your Own Compiler

Chapter 3 Structured Program Development

Our Strategy for Learning Fortran 90

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

C++ Programming: From Problem Analysis to Program Design, Third Edition

5) Debugging and error trapping

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Unit 1 Lesson 4. Introduction to Control Statements

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

TED Language Reference Manual

1 Lexical Considerations

CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

You will have mastered the material in this chapter when you can:

Programming for Engineers Iteration

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

UNIT- 3 Introduction to C++

Course Outline. Introduction to java

C++ Programming: From Problem Analysis to Program Design, Third Edition

INTRODUCTION 1 AND REVIEW

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

COMS 469: Interactive Media II

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

More Programming Constructs -- Introduction

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

QUIZ: What value is stored in a after this

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

Operators and Expressions

Chapter 3: Operators, Expressions and Type Conversion

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Chapter 12 Variables and Operators

1 Chapter Plan...1 Exercise - Simple Program...2

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Example. CS 201 Selection Structures (2) and Repetition. Nested if Statements with More Than One Variable

Chapter 2. C++ Basics

Chapter 2: Functions and Control Structures

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

In this chapter you ll learn:

Typescript on LLVM Language Reference Manual

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

Pace University. Fundamental Concepts of CS121 1

C - Basic Introduction

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Preface Introduction... 23

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter Overview. More Flow of Control. Flow Of Control. Using Boolean Expressions. Using Boolean Expressions. Evaluating Boolean Expressions

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

CSCI 1061U Programming Workshop 2. C++ Basics

Chapter Overview. C++ Basics. Variables and Assignments. Variables and Assignments. Keywords. Identifiers. 2.1 Variables and Assignments

LECTURE 5 Control Structures Part 2

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

Self-test TSO/E REXX. Document: e0167test.fm 19/04/2012. ABIS Training & Consulting P.O. Box 220 B-3000 Leuven Belgium

Full file at

8. Control statements

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

Chapter 2 Working with Data Types and Operators

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

C++ Programming: From Problem Analysis to Program Design, Third Edition

CSI33 Data Structures

Transcription:

Chapter 2 REXX STATEMENTS SYS-ED/ Computer Education Techniques, Inc.

Objectives You will learn: Variables. REXX expressions. Concatenation. Conditional programming and flow of control. Condition traps. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page i

1 Variables 1.1 Variable Name Variable names may consist of the following characters: A-Z a-z 0-9 @ # $?!. _ The first character cannot be a period or digit. The maximum size for a variable name is 250 characters. Variables need to be used properly in order to code an efficient REXX program. The use of special names, such as RC, SIGL, or RESULT, as variable names will result in errors and unpredictable results. This assignment would be confusing. data = data 1.2 Simple Variable A simple variable contains a single data item; its value is set with commands. A variable can contain numbers or character strings. Variables do not have to be declared. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 1

1.3 Compound Variables With the REXX programming language, a compound variable typically is referred to as an array; it consists of a list of elements identified by a single name. A specific value can be established with an assignment statement. monthtbl.2 = 345 monthtbl.mon = amt Multi dimensional tables also can be used. Compound variables often are used with DO loops or repetitive loops. daily_stats.month.day = amt A stem can be used to initialize the entire array. monthtbl. = 0 SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 2

2 Expressions Expressions can be used within a REXX clause consisting of: Constants Operators Comparisons operators Logical operators 2.1 Constants These constants are used to perform arithmetic in REXX. Whole number Decimal number Floating point number Signed number These operators are used in REXX expressions: 2.2 Operators + Add. - Subtract. * Multiply. / Divide. % Divide and return a whole number. // Divide and return the remainder only. ** Exponentiation. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 3

2.3 Comparison Operators These comparison operators are used in REXX expressions: = Equal. == Strictly equal. \= Not equal. \== Not strictly equal. > Greater than. < Less than. >= Greater than or equal. <= Less than or equal. \< Not less than. \> Not greater than. Strictly equal and not strictly equal requires that all characters including the case, type, and number of spaces be identical. IF salary > 200000 & age < 25 & sex = 'F' THEN SAY 'Are you single? Order of Operation The precedence rules adhere to the following order of operation: -+ Prefix Operators. ** Exponentiation. * / % // Multiplication and Division. +- Addition and Subtraction. /*******REXX************/ PARSE ARG amount tax total = amount + (amount * tax) /* total including taxes */ SAY 'Your total bill is ' total SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 4

Logical expressions return a value of 0 or 1. 2.4 Logical Operators The logical operators are: & AND OR && Exclusive OR Logical NOT IF overtime > 100 & evaluation = 'E' THEN salary = salary * 1.10 else salary = salary *.90 counter = 1 SAY counter = 0 /* What is displayed */ SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 5

3 Concatenation There are different ways of combining data; the operation is known as concatenation. The data can be expressions, strings, variables and constants. Concatenation of is used to format output. The following operators are available: Blank Concatenate and place a single space in between: SAY fld1 fld2 Concatenate without spaces in between: Abuttal SAY (10/2) (2*2) Concatenate and place no blanks in between: SAY amt'db' SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 6

4 IF/THEN The IF statement allows instructions to be executed conditionally. Nested IF statements also are permitted. When the entire IF is placed on a single line, the ELSE must be separated with a semicolon. When more than one instruction is to be executed, use the DO statement. The format of the IF statement is: IF expression THEN instruction [ELSE instruction] IF expression THEN instruction[; ELSE instruction] IF salary > 1000000 THEN DO SAY 'Do you want to go to lunch? Its your treat' PULL ans A NOP: No operation instruction is a dummy instruction. The NOP instruction can be used when no operations are necessary. IF weather = 'fine' THEN DO SAY "What a great day " IF POOL = 'open' THEN SAY "Let's go for a dip" ELSE NOP ELSE SAY "Need your raincoat?" SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 7

5 SELECT Statement The SELECT statement is used for evaluating a number of choices. It is easier to maintain and program than a series of nested statements. The first WHEN statement that has a true value is executed. After it executes the first true WHEN, all other WHEN statements are ignored. The OTHERWISE is executed if none of the WHENs are true. If more than one instruction is to be executed, then the DO/ statement should be used. The exception is the OTHERWISE which does not require a DO or. OTHERWISE would be the required clause. The format of the SELECT statement is: SELECT WHEN expression THEN instruction(s) WHEN expression THEN instruction(s).. OTHERWISE instruction(s) SELECT WHEN month = 4 month = 6 month = 9 month = 11 THEN days = 30 WHEN month = 2 THEN days = 28 OTHERWISE days = 31 SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 8

5.1 SELECT Statement Walkthrough Code a REXX program using the SELECT statement to perform the following steps: 1. Obtain from the operator: - # of years programming experience - Operators age, sex, and name 2. Display one of the following messages: Condition EXPERIENCE <1 YEAR EXPERIENCE BETWEEN 1 AND 3 YEARS AND FEMALE EXPERIENCE BETWEEN 1 AND 3 YEARS AND MALE MORE THAN 3 YEARS EXPERIENCE AND FEMALE MORE THAN 3 YEARS EXPERIENCE AND MALE Message YOU ARE A BABY PROGRAMMER HELLO, MS HELLO, MR HER HIGHNESS YOUR GREATNESS ' 3. Fill in the underscores with the operator s name. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 9

There are two categories of REXX loops: 6 DO Loops Repetitive loops repeat a certain number of times. Conditional loops repeat based on a condition. Both repetitive and conditional loops are supported by REXX. The format of the repetitive loops statement is: DO number-times instructions With a control variable, the loop can be repeated and the variable incremented. The control variable automatically increases by the incr amount. The default is 1. DO numb = start TO end BY incr instructions Examples: looper = 5 DO looper SAY "HI YA ALL" DO I = 1 to 5 SAY I DO I = 1 TO 10 BY 2 SAY I SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 10

Examples: DO COUNT = 1 SAY COUNT IF COUNT = 10 THEN LEAVE DO PTR = 12 BY -2 TO 7 SAY 'COUNT BACKWARDS ' PTR DO COUNT =1 to 50 DO CITY=1 to 10 say 'GIVE Next City Population.' say 'of state', COUNT Pull CITYPOP COUNTRY.COUNT.CITY=CITYPOP SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 11

7 DO FOREVER DO FORERVER is an infinite loop that can be used to keep executing logic until a null key is entered. The format of the DO FOREVER statement is: DO FOREVER instructions. DO FOREVER SAY "ENTER DATA SET TO BE DELETED" PULL DSN IF DSN = '' THEN LEAVE "DELETE" DSN SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 12

8 LEAVE and ITERATE Instructions The LEAVE instruction causes an immediate exit from the loop. Control is then transferred to the statement after the. The format of the LEAVE instruction is: LEAVE [name] The ITERATE instruction passes control to the DO to continue with the next control variable or to continue the loop. The format of the ITERATE instruction is: ITERATE [name] If a control variable is detected it is incremented or decremented, based on the values in the DO. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 13

9 DO WHILE and UNTIL Instructions The DO WHILE and UNTIL statements are conditional loops repeat based on a condition The WHILE instruction loop executes the loop while the condition is true; the logic validation is performed at the top of the loop. The format of the DO WHILE expression is: DO WHILE expression instructions If the condition is false the first time into the loop, the loop is bypassed. The LEAVE statement is used for exiting from the loop. The UNTIL loops when a condition is not true; execution of the loop will continue until the condition evaluates to true. Since the check is at the end of the loop. The loop always executes at least once The format of the DO UNTIL expression is: DO UNTIL expression instructions DO loops can be nested. Examples: I = 0 FLAG = 'T' DO WHILE FLAG = 'T' I = I + 1 IF I = 10 THEN FLAG = 'F' SAY I DO UNTIL pass = password SAY "ENTER password" PULL pass SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 14

10 EXIT Statement The EXIT is used to unconditionally terminate a REXX procedure and return to where the procedure was invoked. The format of the EXIT code is: EXIT code The termination usually returns control back to TSO/ISPF; however it can be invoked and returned to the SELECT services of Dialog Manager or to another procedure. The EXIT also can return a single value to the invoking procedure. If the invoking procedure is a REXX routine, the valued passed back is in the special variable called RESULT. DO FOREVER SAY 'Do you want to continue (Y/N) ' PULL response IF response = 'N' THEN EXIT.. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 15

11 SIGNAL Statement The format 1 of the SIGNAL statement can be used to pass control to a label in the program, such as a GOTO type statement. SIGNAL does not provide the return capabilities of a subroutine or function. Over use of the SIGNAL statement will make program maintenance more difficult. The format 2 of the SIGNAL statement is very useful. It causes REXX to branch to the label ERROR. If an error is detected, which occurs when a host statement has a non zero condition code in the program, SIGL will contain the line number of the statement that caused the transfer. The formats of the SIGNAL statement are: SIGNAL label SIGNAL ON ERROR NAME label SIGNAL looper looper: /* Example of REXX SIGNAL ON ERROR */ SIGNAL ON ERROR "ALLOC DA(SAMPLE.DATA) DD(INPFILE) SHR"... ERROR: SAY "An error was detected on line " SIGL SAY "The Return Code is " RC SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 16

12 Condition Traps These condition traps can be used in the SIGNAL command. ERROR FAILURE HALT NOVALUE SYNTAX Error in host instruction. Traps all positive and negative return codes. Error in host instruction. Traps all negative return codes. Attempt to cause an external interrupt. For example, the HI command. Unutilized variable. Syntax error on REXX interpretation of a command. SYS-ED/COMPUTER EDUCATION TECHNIQUES, INC. (REXX Prg - 11.3) Ch 2: Page 17