Quite often one needs loops which, in the last iteration, execute only part of the loop body.



Goal

Demonstrate the best way to do this.



Task

Write a loop which writes the comma-separated list

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

using separate output statements for the number
and the comma from within the body of the loop.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


 
*        Loops/N plus one half     13/08/2015
LOOPHALF CSECT         USING  LOOPHALF,R12
         LR     R12,R15
BEGIN    LA     R3,MVC
         SR     R5,R5
         LA     R6,1
         LA     R7,10
LOOPI    BXH    R5,R6,ELOOPI       for i=1 to 10
         XDECO  R5,XDEC
         MVC    0(4,R3),XDEC+8
         LA     R3,4(R3)
         CH     R5,=H'10'
         BNL    NEXTI
         MVC    0(2,R3),=C', '
         LA     R3,2(R3)
NEXTI    B      LOOPI              next i
ELOOPI   XPRNT  MVC,80
         XR     R15,R15
         BR     R14
MVC      DC     CL80' '
XDEC     DS     CL12
         YREGS  
         END    LOOPHALF
 