Talk:Loops/With multiple ranges: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎other DO loop cases: added a new section.)
Line 34: Line 34:


: 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.   -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:26, 15 September 2018 (UTC)
: 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.   -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 23:26, 15 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. &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 00:56, 16 September 2018 (UTC)

Revision as of 00:57, 16 September 2018

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 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 modified.)
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).
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)

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)