Lesson 6. 05 NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry)

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

Fundamental of C programming
8-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Lesson 5 - Decision Structure By: Dan Lunney
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
ITEC113 Algorithms and Programming Techniques
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Logical Operators and Conditional statements
Chapter 4 Making Decisions
C++ for Engineers and Scientists Third Edition
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Chapter 4 Selection Structures: Making Decisions.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Making Decisions Chapter 5.  Thus far we have created classes and performed basic mathematical operations  Consider our ComputeArea.java program to.
Making Decisions. 4.1 Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
CPS120: Introduction to Computer Science Decision Making in Programs.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
Chapter 3 Decision Making. What is IF? The primary method of changing the flow of a program is by making decisions using the IF verb. The following example.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Chapter 8 Decision Making Using the IF and EVALUATE Statements.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Chapter 8 – Data Validation
Chapter Making Decisions 4. Relational Operators 4.1.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
A First Book of C++ Chapter 4 Selection.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Computer Science 1000 LOGO II. Boolean Expressions like Excel and Scratch, LOGO supports three Boolean operators less than (
Chapter 4: Decisions and Conditions
LOGICAL CONTROL STRUCTURES (chp. 8)
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
The Selection Structure
Chapter 4: Making Decisions.
Chapter 3 The DATA DIVISION.
Control Structures: Selection Statement
Visual Basic – Decision Statements
Chapter 5: Control Structure
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
CHAPTER 5: Control Flow Tools (if statement)
Chapter 3: Selection Structures: Making Decisions
Control Structures: Selection Statement
Any Questions?.
The Selection Structure
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

Lesson 6

05 NUMERIC-FIELDPIC 9(5). 05 ALPHANUMERIC-FIELDPIC X(5).... IF NUMERIC-FIELD = 10...(valid entry) IF NUMERIC-FIELD = ‘10’... (invalid entry) IF ALPHANUMERIC-FIELD = 10(invalid entry) IF ALPHANUMERIC-FIELD = ‘10’(valid entry) The Relational Condition (a) Syntax (b) Examples IS [NOT] GREATER THAN IS [NOT] > IS [NOT] LESS THAN identifier-1IS [NOT] = IS [NOT] LESS THAN OR EQUAL TO IS [NOT] <=

CONDITION? STATEMENT2 STATEMENT1 STATEMENT3 CONDITION? STATEMENT1 STATEMENT2 The IF Statement (a) With ELSE Option (b) Without ELSE Option FALSE TRUE

The ELSE Clause/II A=B MOVE ZERO TO C MOVE 1 TO C WRITE DETAIL-LINE MOVE ZERO TO D MOVE 1 TO D FALSETRUE IF A = B MOVE 1 TO C MOVE 1 TO D ELSE MOVE ZERO TO C MOVE ZERO TO D END-IF. WRITE DETAIL-LINE. (a) IF/ELSE Flowchart(b) COBOL Code

Nested IF Statements/II C>D? ADD 1 TO Y ADD 1 TO X A>B? FALSE TRUE IF A > B IF C > D ADD 1 TO X ELSE NEXT SENTENCE ELSE ADD 1 TO Y. IF A > B IF C > D ADD 1 TO X END-IF ELSE ADD 1 TO Y END-IF (b) NEXT SENTENCE (COBOL-74) (c) Scope Terminators (COBOL-85) (a) Flowchart

IBM COBOL Reference Manual: ‘The presence of one or more IF statements within the initial IF statement constitutes a "nested IF statement." Nesting statements is much like specifying subordinate arithmetic expressions enclosed in parentheses and combined in larger arithmetic expressions.’ Nested IF’s

IF A = B NEXT SENTENCE ELSE PERFORM D0-ARITHMETIC-CALCULATIONS END-IF. IF condition A = B is true then NEXT SENTENCE is executed and the ELSE phrase is ignored, and control passes to the statement following the END-IF.

The Class Test NUMERIC ALPHABETIC IF identifier IS [NOT]ALPHABETIC-UPPER ALPHABETIC-LOWER (a) Syntax 05 NUMERIC-FIELDPIC 9(5). 05 ALPHABETIC-FIELDPIC X(5).... IF NUMERIC-FIELD IS NUMERIC PERFORM D0-ARITHMETIC-CALCULATIONS END-IF. IF NUMERIC-FIELD IS NOT NUMERIC DISPLAY ‘ERROR - NUMERIC FIELD CONTAINS INVALID DATA’ END-IF. IF ALPHABETIC-FIELD IS ALPHABETIC DISPLAY ‘ALPHABETIC FIELD CONTAINS UPPER AND/OR LOWER CASE LETTERS’ END-IF. IF ALPHABETIC-FIELD IS NOTALPHABETIC DISPLAY ‘ERROR - ALPHABETIC FIELD CONTAINS NON-ALPHABETIC DATA’ END-IF. (b) Examples

The SignTest identifierPOSITIVE IF arithmetic expression IS [NOT]NEGATIVE ZERO (a) Syntax IF NET-PAY IS NOT POSITIVE PERFORM TOO-MUCH-TAXES END-IF. IF CHECK-BALANCE IS NEGATIVE PERFORM OVERDRAWN END-IF. (b) Examples

Condition Names (88-level entries) (a) Syntax 05 YEAR-CODEPIC FRESHMANVALUE SOPHOMOREVALUE JUNIORVALUE SENIORVALUE GRAD-STUDENTVALUES ARE 5 THRU UNDER-CLASSMANVALUES ARE 1, 2 88 UPPER-CLASSMANVALUES ARE 3, VALID-CODESVALUES ARE 1 THRU 8. IF FRESHMAN PERFORM WELCOME-NEW-STUDENTS END-IF IF VALID-CODES PERFORM PROCESS-STUDENT-RECORD ELSE DISPLAY ‘INCOMING YEAR CODE IS IN ERROR’ END-IF. (b) Examples VALUE ISTHROUGH 88 data-name VALUES AREliteral-1 THRU literal-2...

Level 88 Identifies any condition-name entry that is associated with a particular value of a conditional variable. Check sample code (program CPCH13B)

The ACCEPT Statement WORKING-STORAGE SECTION. 01 EMPLOYEE-RECORD EMP-DATE-OF-BIRTH. 10 EMP-BIRTH-MONTHPIC EMP-BIRTH-YEARPIC EMPLOYEE-AGEPIC 99V DATE-WORK-AREA. 05 TODAYS-YEARPIC TODAYS-MONTHPIC TODAYS-DAYPIC PROCEDURE DIVISION... ACCEPT DATE-WORK-AREA FROM DATE... COMPUTE EMPLOYEE-AGE = TODAYS-YEAR - EMP-BIRTH-YEAR + (TODAYS-MONTH - EMP-BIRTH-MONTH) / 12.