This code, developed to run under TSO/E REXX, was designed as a further demonstration of STEM variable processing, by using a STEM variable to hold a short list of names which require sorting.
/* REXX Workshop 2 - Sort the incoming names into order & print */
name. = 'Z'; /* Stem variable to receive gotten names. */
names = ''; ans = ''; sorted =''; i = 1;
/*
First let's collect the names.
*/
Do Forever /* Phase 1 - Read all the names. */
Say "Enter a name:"
PULL ans .
If ans = '****' Then Leave;
name.i = ans;
i = i + 1;
End;
i = i - 1; Say i '- names read.'; Say ' ';
/*
Now let's sort the names.
*/
Do Forever /* Phase 2 - Sort the names. */
If sorted = 'Y' Then Leave;
sorted = 'Y'; n1 = 1; n2 = 2; n3 = 0;
Do n3 =1 to i
Select
When name.n1 > name.n2 Then
Do
x = name.n2
name.n2 = name.n1
name.n1 = x
sorted = 'N'
End
Otherwise
Nop
End
n1 = n1 + 1; n2 = n2 + 1;
End;
End;
n1 = 1;
Do Forever /* Phase 3 - Output the names. */
If n1 > i Then Leave
names = names || name.n1 || ' ';
n1 = n1 + 1;
End;
Say names
Say 'Workshop 2 - Successfully completed.'
Exit 0 /* leave program */
Compare this with the TSO/E REXX version by clicking here.
Copyright © KMS-IT Limited 2002