Talk:Loops/With multiple ranges

From Rosetta Code
Revision as of 08:08, 16 September 2018 by rosettacode>Paddy3118 (→‎Further explanation needed: Further explanation to further explanation needed, given?)

Further explanation needed

You can't expect RC coders to understand your programming language. You shold convert to some form of pseudo-code and explanation in English.
It would also help if you went step-by-step through a single, two and maybe three ranges should produce - in a mix of pseudo-code and English. Thanks. --Paddy3118 (talk) 19:05, 15 September 2018 (UTC)

I thought that a   do   loop would be self explanatory   (even with such an old language as PL/I, conceived in 1963 or earlier as a possible extension to FORTRAN, announced in 1964, delivered in 1966)   with the same degree that when a   for   loop is used in pseudo-code,   but is never described.   An astonishing number of pseudo-code on Wikipedia and Rosetta Code uses (a)   C   (or C-type)   language,   but I have yet to see a   for   loop explained/described in the form of pseudo-code.   One reason that multiple ranges for the   do   loop were chosen for this task (along with expressions in the various ranges) was to ensure that short-cuts weren't chosen to bypass the logic and expressiveness of the original code   (for maintainability and range expanding, for example),   and also to have some method of verification that the various ranges were indeed, executed correctly.   One such concern was:
        do j=1  to 100,   200  to 300;
        say j;
        end;
─── being executed as:
        do j=1  to 300
        if j>100  &  j<200  then iterate
        say j
        end
─── or:
        do j=1  to 300
        if j<=100 | j>=200  then say j
        end
(both of which are slightly harder to comprehend as compared to the original case code, and harder to modify if the original ranges are changed or their "step" (incrementation) values are either modified or added.)   Also of note is that in the later two cases, the variable   j   will have more values assigned to it over the execution of the   do   loop.
The main intent was to show how various languages would or could utilize multiple ranges of   do   loops,   not to show how a   do   loop works.   I had assumed that almost everyone knew how   do   loops worked,   it was the use of multiple ranges that was the point of this task.     I had assumed that once other popular languages were entered (most of which would probably use a   for   construction or something similar),   that other people would understand how a   do   loop worked.   I had carefully chosen the ranges to   not   use a range that some languages would behave differently   (which would make a nice task addition to Rosetta Code, by the way ─── this is one area that is seldom explored when comparing languages here on Rosetta Code).
For instance:
        n=75
             do j=100  to n
             say j   
             end
─── where some languages will not produce any output   (not testing the range before execution of the do loop at least once),   other languages (such as PL/I and REXX) will test at the start (head) of the   do   loop.
However, I'll take a stab at adding pseudo-code to explain   do   loops as used by the PL/I language.   By the way, PL/I isn't my language, it's been years since I even had access to a PL/I compiler, that is the only reason that I didn't enter a PL/I example (here and in other Rosetta Code tasks).   If I had access to a PL/I compiler, I'd be entering numerous PL/I examples;   PL/I syntax is very similar to REXX's, and indeed, REXX borrowed a lot of PL/I's syntax and PL/I's BIFs.   -- Gerard Schildberger (talk) 23:26, 15 September 2018 (UTC)

Hi Gerard, I would first like to say that after first reading the task description:

  • I really liked what seemed to me the central idea of the task: looping over multiple ranges with only the single loop body.
  • I didn't like the initial reliance on the PL/I code; although PL/I served the crucial requirement of making you come up with the idea, I thought that its variable initialisation and explicit language syntax didn't add to the description.

I was also lazy and didn't try and give an example for discusion of my ideas.

Here's more of what I was thinking of

Some languages allow for the easy looping around a single block of code using a variable that iterates through several ranges of values in succession. In pseudocode:

LOOP variable J over range(-3 to 9 by  3) then range(30 to 24 by -2) then range(startfunc(x) to stopfunc(x) by stepfunc(x))
BEGIN
    /* do_loop_body */
    print_variable_followed_by_space(J)
END; /* LOOP */
print_newline()

The PL/I code could be rewritten in such pseudocode, or the task itself altered to ask for not much more than what is stated above. (I would need to add that ranges are inclusive of endpoints and what the three funcs do when computing a ranges limits).

What do you think Gerard? --Paddy3118 (talk) 08:07, 16 September 2018 (UTC)

other DO loop cases

Another good tasks for Rosetta Code would be the case of how a language treats the following code snippets: <lang>k= 5 L= 2

      do j=k  to  L 
      say  j
      end</lang>

and show what values (if any) are displayed.

Or, another case: <lang>k= 5 L= 2

      do j=L  to k  by -2 
      say  j
      end</lang>

Or, yet another case: <lang>k= 5 L= 2

      do j=L  to k  by -2 
      say  j
      k= 9
      end</lang>

But I don't want to go through explaining those in pseudo-code.   -- Gerard Schildberger (talk) 00:56, 16 September 2018 (UTC)