Logo

dev-resources.site

for different kinds of informations.

COBOL Tutorial Series: Loop statements - Session 4

Published at
10/19/2024
Categories
cobol
development
tutorial
banking
Author
ngtduc693
Author
9 person written this
ngtduc693
open
COBOL Tutorial Series: Loop statements - Session 4

Hello, I'm Duke

In the previous 3 sessions, I have guided you on how to develop, compile, and create a simple calculation program with condition statements using COBOL.

Today, I will be giving a tutorial on loops in COBOL.

1. In-line Perform
The statements inside PERFORM will be executed until END-PERFORM is reached.

2. Perform Varying

In perform varying, a paragraph will be executed till the condition in Until phrase becomes true.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ProductList.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-PRODUCT-NAME        PIC X(30).
       01 WS-PRODUCT-PRICE       PIC 9(5)V99.
       01 WS-TOTAL-PRICE         PIC 9(7)V99 VALUE 0.
       01 WS-COUNTER             PIC 9(2) VALUE 1.
       01 WS-NUMBER-OF-PRODUCTS  PIC 9(2) VALUE 0.

       PROCEDURE DIVISION.
       MAIN-PROCESS.                
           DISPLAY "How many products?".
           ACCEPT WS-NUMBER-OF-PRODUCTS.

           PERFORM VARYING WS-COUNTER FROM 1 BY 1
            UNTIL WS-COUNTER > WS-NUMBER-OF-PRODUCTS
             DISPLAY "Name of product no. " WS-COUNTER ": "
             ACCEPT WS-PRODUCT-NAME 
             DISPLAY "Price of " WS-PRODUCT-NAME ": "
             ACCEPT WS-PRODUCT-PRICE

             COMPUTE WS-TOTAL-PRICE = WS-TOTAL-PRICE + WS-PRODUCT-PRICE
           END-PERFORM.             

           DISPLAY "Total price: " WS-TOTAL-PRICE.
           STOP RUN. 

Enter fullscreen mode Exit fullscreen mode
  • WS-PRODUCT-NAME: This variable is used to store the product name, with a maximum of 30 characters (PIC X(30)).
  • WS-PRODUCT-PRICE: This variable is used to store the product price in a 5-digit and 2-decimal number format (PIC 9(5)V99).
  • WS-TOTAL-PRICE: This variable stores the total price of all products, initialized with the value 0. It has a 7-digit and 2-decimal format (PIC 9(7)V99).
  • WS-COUNTER: This variable is a counter, starting from 1 and has a 2-digit format (PIC 9(2)).
  • WS-NUMBER-OF-PRODUCTS: This variable stores the number of products entered by the user, initialized with the value 0
  • PERFORM VARYING: Starts a loop. This loop will continue until WS-COUNTER is greater than WS-NUMBER-OF-PRODUCTS.
  • FROM 1 BY 1: Sets the starting value of WS-COUNTER to 1 and increments it by 1 after each iteration.

and here is the result

result

Repository here

banking Article's
30 articles in total
Favicon
Is it easy to manage a team of highly qualified engineers?
Favicon
Advantages of Open Banking on Retail Investment
Favicon
Open Banking: Revolutionising the future of financial services
Favicon
Understanding PostgreSQL Isolation Levels
Favicon
How Virtual CFO Services Empower Small and Medium Enterprises (SMEs)
Favicon
How to Secure Your Cash App Account After Buying
Favicon
Buy Verified Cashapp and Streamline Your Workflow
Favicon
SEOSiri | AI-Powered Finance: A Strategic Playbook for EU Financial Service Providers
Favicon
Embracing the Cloud for Banking Innovation
Favicon
Effective Logging with ILogger in USSD Banking Applications: A .NET Approach
Favicon
AI in Finance: Transforming Banking and Investment
Favicon
Streamlining Compliance and Risk Management in Banking through RPA
Favicon
Embarking on the Digital Frontier: Decoding the World of Banking Applications
Favicon
Cloud Computing in Banking: Enhancing Efficiency and Security
Favicon
RPA Implementation Services for Banking: Essential Insights for 2024
Favicon
Data Engineering in Observability: The Backbone of Modern Monitoring
Favicon
Investment Banking in Emerging Markets: Opportunities and Challenges
Favicon
Innovation Unleashed: The Crucial Role of Banking Software Development
Favicon
COBOL Tutorial Series: Condition (IF, ELSE) statement - Session 3
Favicon
COBOL Tutorial Series: A calculation program - Session 2
Favicon
COBOL Tutorial Series: Loop statements - Session 4
Favicon
COBOL Tutorial Series: Developing Without a Mainframe - Session 1
Favicon
Mastering Equity Research Industry Analysis and Company Valuation
Favicon
Investment Banking Automation: Transforming the Future of Finance
Favicon
Mobile Banking App Development Costs - AI and Blockchain
Favicon
The Future of Banking: How Video KYC is Transforming Customer Onboarding
Favicon
What Are API Banking Services and How Can They Benefit You?
Favicon
Recurring Payments Simplified: How Flutterwave Static Virtual Accounts Can Transform Your Business
Favicon
How to Find and Hire the Best Fintech Developer
Favicon
Importance of Offshoring in Investment Banking

Featured ones: