June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -12,6 +12,18 @@ using separate output statements for the number
|
|||
and the comma from within the body of the loop.
|
||||
|
||||
|
||||
;Related task:
|
||||
* [[Loop/Break]]
|
||||
;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]]
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
'BEGIN'
|
||||
'COMMENT' Loops N plus one half - Algol60 - 20/06/2018;
|
||||
'INTEGER' I;
|
||||
'FOR' I:=1 'STEP' 1 'UNTIL' 10 'DO' 'BEGIN'
|
||||
OUTINTEGER(1,I);
|
||||
'IF' I 'NOTEQUAL' 10 'THEN' OUTSTRING(1,'(', ')')
|
||||
'END'
|
||||
'END'
|
||||
|
|
@ -1,14 +1,11 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Loop_And_Half is
|
||||
I : Positive := 1;
|
||||
procedure LoopsAndHalf is
|
||||
begin
|
||||
loop
|
||||
Put(Item => I, Width => 1);
|
||||
exit when I = 10;
|
||||
Put(", ");
|
||||
I := I + 1;
|
||||
end loop;
|
||||
New_Line;
|
||||
end Loop_And_Half;
|
||||
for i in 1 .. 10 loop
|
||||
Ada.Text_IO.put (i'Img);
|
||||
exit when i = 10;
|
||||
Ada.Text_IO.put (",");
|
||||
end loop;
|
||||
Ada.Text_IO.new_line;
|
||||
end LoopsAndHalf;
|
||||
|
|
|
|||
|
|
@ -1,49 +1,5 @@
|
|||
C WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
|
||||
C two nonstandard characters on the lines labelled 5001 and 5002.
|
||||
C Many F77 compilers should be okay with it, but it is *not*
|
||||
C standard.
|
||||
PROGRAM LOOPPLUSONEHALF
|
||||
INTEGER I, TEN
|
||||
C I'm setting a parameter to distinguish from the label 10.
|
||||
PARAMETER (TEN = 10)
|
||||
|
||||
DO 10 I = 1, TEN
|
||||
C Write the number only.
|
||||
WRITE (*,5001) I
|
||||
|
||||
C If we are on the last one, stop here. This will make this test
|
||||
C every iteration, which can slow your program down a little. If
|
||||
C you want to speed this up at the cost of your own convenience,
|
||||
C you could loop only to nine, and handle ten on its own after
|
||||
C the loop is finished. If you don't care, power to you.
|
||||
IF (I .EQ. TEN) GOTO 10
|
||||
|
||||
C Append a comma to the number.
|
||||
WRITE (*,5002) ','
|
||||
10 CONTINUE
|
||||
|
||||
C Always finish with a newline. This programmer hates it when a
|
||||
C program does not end its output with a newline.
|
||||
WRITE (*,5000) ''
|
||||
STOP
|
||||
|
||||
5000 FORMAT (A)
|
||||
|
||||
C Standard FORTRAN 77 is completely incapable of completing a
|
||||
C WRITE statement without printing a newline. This program would
|
||||
C be much more difficult (i.e. impossible) to write in the ANSI
|
||||
C standard, without cheating and saying something like:
|
||||
C
|
||||
C WRITE (*,*) '1, 2, 3, 4, 5, 6, 7, 8, 9, 10'
|
||||
C
|
||||
C The dollar sign at the end of the format is a nonstandard
|
||||
C character. It tells the compiler not to print a newline. If you
|
||||
C are actually using FORTRAN 77, you should figure out what your
|
||||
C particular compiler accepts. If you are actually using Fortran
|
||||
C 90 or later, you should replace this line with the commented
|
||||
C line that follows it.
|
||||
5001 FORMAT (I3, $)
|
||||
5002 FORMAT (A, $)
|
||||
C5001 FORMAT (T3, ADVANCE='NO')
|
||||
C5001 FORMAT (A, ADVANCE='NO')
|
||||
C Loops N plus one half - Fortran IV (1964)
|
||||
INTEGER I
|
||||
WRITE(6,301) (I,I=1,10)
|
||||
301 FORMAT((I3,','))
|
||||
END
|
||||
|
|
|
|||
|
|
@ -1,8 +1,49 @@
|
|||
i = 1
|
||||
do
|
||||
write(*, '(I0)', advance='no') i
|
||||
if ( i == 10 ) exit
|
||||
write(*, '(A)', advance='no') ', '
|
||||
i = i + 1
|
||||
end do
|
||||
write(*,*)
|
||||
C WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
|
||||
C two nonstandard characters on the lines labelled 5001 and 5002.
|
||||
C Many F77 compilers should be okay with it, but it is *not*
|
||||
C standard.
|
||||
PROGRAM LOOPPLUSONEHALF
|
||||
INTEGER I, TEN
|
||||
C I'm setting a parameter to distinguish from the label 10.
|
||||
PARAMETER (TEN = 10)
|
||||
|
||||
DO 10 I = 1, TEN
|
||||
C Write the number only.
|
||||
WRITE (*,5001) I
|
||||
|
||||
C If we are on the last one, stop here. This will make this test
|
||||
C every iteration, which can slow your program down a little. If
|
||||
C you want to speed this up at the cost of your own convenience,
|
||||
C you could loop only to nine, and handle ten on its own after
|
||||
C the loop is finished. If you don't care, power to you.
|
||||
IF (I .EQ. TEN) GOTO 10
|
||||
|
||||
C Append a comma to the number.
|
||||
WRITE (*,5002) ','
|
||||
10 CONTINUE
|
||||
|
||||
C Always finish with a newline. This programmer hates it when a
|
||||
C program does not end its output with a newline.
|
||||
WRITE (*,5000) ''
|
||||
STOP
|
||||
|
||||
5000 FORMAT (A)
|
||||
|
||||
C Standard FORTRAN 77 is completely incapable of completing a
|
||||
C WRITE statement without printing a newline. This program would
|
||||
C be much more difficult (i.e. impossible) to write in the ANSI
|
||||
C standard, without cheating and saying something like:
|
||||
C
|
||||
C WRITE (*,*) '1, 2, 3, 4, 5, 6, 7, 8, 9, 10'
|
||||
C
|
||||
C The dollar sign at the end of the format is a nonstandard
|
||||
C character. It tells the compiler not to print a newline. If you
|
||||
C are actually using FORTRAN 77, you should figure out what your
|
||||
C particular compiler accepts. If you are actually using Fortran
|
||||
C 90 or later, you should replace this line with the commented
|
||||
C line that follows it.
|
||||
5001 FORMAT (I3, $)
|
||||
5002 FORMAT (A, $)
|
||||
C5001 FORMAT (T3, ADVANCE='NO')
|
||||
C5001 FORMAT (A, ADVANCE='NO')
|
||||
END
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
i = 1
|
||||
do
|
||||
write(*, '(I0)', advance='no') i
|
||||
if ( i == 10 ) exit
|
||||
write(*, '(A)', advance='no') ', '
|
||||
i = i + 1
|
||||
end do
|
||||
write(*,*)
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
loop :: IO ()
|
||||
loop = mapM_ action [1 .. 10]
|
||||
where action n = do
|
||||
main :: IO ()
|
||||
main = forM_ [1 .. 10] $ \n -> do
|
||||
putStr $ show n
|
||||
putStr $ if n == 10 then "\n" else ", "
|
||||
|
|
@ -0,0 +1 @@
|
|||
intercalate ", " (map show [1..10])
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
foreach my $i (1..10) {
|
||||
for my $i(1..10) {
|
||||
print $i;
|
||||
last if $i == 10;
|
||||
print ', ';
|
||||
|
|
@ -0,0 +1 @@
|
|||
print join(', ', 1..10), "\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue