Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,569 questions

56,787 answers

573 users

How to write a loop with a specified step in COBOL

2 Answers

0 votes
IDENTIFICATION DIVISION.
PROGRAM-ID. SPECIFIEDSTEPLOOP. 

DATA DIVISION.
WORKING-STORAGE SECTION.
01  I            PIC 99 VALUE 0.
01  STEP-SIZE    PIC 99 VALUE 3.

*> Loop With a Custom Step
PROCEDURE DIVISION.
    DISPLAY "LOOP WITH STEP SIZE OF " STEP-SIZE.

    PERFORM VARYING I FROM 0 BY STEP-SIZE
          UNTIL I > 20
        DISPLAY "I = " I
    END-PERFORM

    DISPLAY "DONE.".
    STOP RUN.




*> run:
*>
*> LOOP WITH STEP SIZE OF 03
*> I = 00
*> I = 03
*> I = 06
*> I = 09
*> I = 12
*> I = 15
*> I = 18
*> DONE.
*>

 



answered Apr 10 by avibootz
0 votes
IDENTIFICATION DIVISION.
PROGRAM-ID. COUNTDOWN-STEP.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  I   PIC S99 VALUE 20.

PROCEDURE DIVISION.
    DISPLAY "COUNTING DOWN BY 2:".

    PERFORM VARYING I FROM 20 BY -2
            UNTIL I < 0
        DISPLAY "I = " I
    END-PERFORM

    DISPLAY "DONE.".
    STOP RUN.
    

  
*> run:
*>
*> COUNTING DOWN BY 2:
*> I = +20
*> I = +18
*> I = +16
*> I = +14
*> I = +12
*> I = +10
*> I = +08
*> I = +06
*> I = +04
*> I = +02
*> I = +00
*> DONE.
*>

 



answered Apr 10 by avibootz
...