WeixiangYan/CodeTransOcean huggingface dataset:
Task: Read a file line by line


C++: #include <fstream>
#include <string>
#include <iostream>

int main( int argc , char** argv ) {
   int linecount = 0 ;
   std::string line  ;
   std::ifstream infile( argv[ 1 ] ) ; 
   if ( infile ) {
      while ( getline( infile , line ) ) {
	 std::cout << linecount << ": " 
                   << line      << '\n' ;  
	 linecount++ ;
      }
   }
   infile.close( ) ;
   return 0 ;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Line_By_Line is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "line_by_line.adb");
   While not  End_Of_File (File) Loop
      Put_Line (Get_Line (File));
   end loop;

   Close (File);
end Line_By_Line;
Task: Read a file line by line




Go: package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

func init() {
	log.SetFlags(log.Lshortfile)
}

func main() {
	
	inputFile, err := os.Open("byline.go")
	if err != nil {
		log.Fatal("Error opening input file:", err)
	}

	
	
	
	defer inputFile.Close()

	scanner := bufio.NewScanner(inputFile)

	
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}

	
	
	if err := scanner.Err(); err != nil {
		log.Fatal(scanner.Err())
	}
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Line_By_Line is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "line_by_line.adb");
   While not  End_Of_File (File) Loop
      Put_Line (Get_Line (File));
   end loop;

   Close (File);
end Line_By_Line;
Task: Read a file line by line





Java: import java.io.BufferedReader;
import java.io.FileReader;


public class ReadFileByLines {
    private static void processLine(int lineNo, String line) {
        
    }

    public static void main(String[] args) {
        for (String filename : args) {
            BufferedReader br = null;
            FileReader fr = null;
            try {
                fr = new FileReader(filename);
                br = new BufferedReader(fr);
                String line;
                int lineNo = 0;
                while ((line = br.readLine()) != null) {
                    processLine(++lineNo, line);
                }
            }
            catch (Exception x) {
                x.printStackTrace();
            }
            finally {
                if (fr != null) {
                    try {br.close();} catch (Exception ignoreMe) {}
                    try {fr.close();} catch (Exception ignoreMe) {}
                }
            }
        }
    }
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Line_By_Line is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "line_by_line.adb");
   While not  End_Of_File (File) Loop
      Put_Line (Get_Line (File));
   end loop;

   Close (File);
end Line_By_Line;
Task: Read a file line by line







Python: for line in lines open('input.txt'):
    print line





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Line_By_Line is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "line_by_line.adb");
   While not  End_Of_File (File) Loop
      Put_Line (Get_Line (File));
   end loop;

   Close (File);
end Line_By_Line;
Task: Read a file line by line








VB: $Include "Rapidq.inc"
dim file as qfilestream

if file.open("c:\A Test.txt", fmOpenRead) then
    while not File.eof
        print File.readline
    wend
else
    print "Cannot read file"
end if

input "Press enter to exit: ";a$




Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Line_By_Line is
   File : File_Type;
begin
   Open (File => File,
         Mode => In_File,
         Name => "line_by_line.adb");
   While not  End_Of_File (File) Loop
      Put_Line (Get_Line (File));
   end loop;

   Close (File);
end Line_By_Line;
Task: Read a file line by line

C: 

#include <conio.h>
#include <stdio.h>

int main()
{
    int n1, n2, n3;

    printf( "\n   Introduzca el primer n%cmero (entero): ", 163 );
    scanf( "%d", &n1 );
    printf( "\n   Introduzca el segundo n%cmero (entero): ", 163 );
    scanf( "%d", &n2 );
    printf( "\n   Introduzca el tercer n%cmero (entero): ", 163 );
    scanf( "%d", &n3 );

    if ( n1 >= n2 && n1 >= n3 )
        printf( "\n   %d es el mayor.", n1 );
    else

        if ( n2 > n3 )
            printf( "\n   %d es el mayor.", n2 );
        else
            printf( "\n   %d es el mayor.", n3 );
 
    getch(); 

    return 0;
}
Task: Read a file line by line



C#: foreach (string readLine in File.ReadLines("FileName"))
  DoSomething(readLine);
Task: Read a file line by line


C++: #include <fstream>
#include <string>
#include <iostream>

int main( int argc , char** argv ) {
   int linecount = 0 ;
   std::string line  ;
   std::ifstream infile( argv[ 1 ] ) ; 
   if ( infile ) {
      while ( getline( infile , line ) ) {
	 std::cout << linecount << ": " 
                   << line      << '\n' ;  
	 linecount++ ;
      }
   }
   infile.close( ) ;
   return 0 ;
}
Task: Read a file line by line





Java: import java.io.BufferedReader;
import java.io.FileReader;


public class ReadFileByLines {
    private static void processLine(int lineNo, String line) {
        
    }

    public static void main(String[] args) {
        for (String filename : args) {
            BufferedReader br = null;
            FileReader fr = null;
            try {
                fr = new FileReader(filename);
                br = new BufferedReader(fr);
                String line;
                int lineNo = 0;
                while ((line = br.readLine()) != null) {
                    processLine(++lineNo, line);
                }
            }
            catch (Exception x) {
                x.printStackTrace();
            }
            finally {
                if (fr != null) {
                    try {br.close();} catch (Exception ignoreMe) {}
                    try {fr.close();} catch (Exception ignoreMe) {}
                }
            }
        }
    }
}
Task: Read a file line by line







Python: for line in lines open('input.txt'):
    print line
Task: Read a file line by line








VB: $Include "Rapidq.inc"
dim file as qfilestream

if file.open("c:\A Test.txt", fmOpenRead) then
    while not File.eof
        print File.readline
    wend
else
    print "Cannot read file"
end if

input "Press enter to exit: ";a$
Task: Read a file line by line




Go: package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

func init() {
	log.SetFlags(log.Lshortfile)
}

func main() {
	
	inputFile, err := os.Open("byline.go")
	if err != nil {
		log.Fatal("Error opening input file:", err)
	}

	
	
	
	defer inputFile.Close()

	scanner := bufio.NewScanner(inputFile)

	
	for scanner.Scan() {
		fmt.Println(scanner.Text())
	}

	
	
	if err := scanner.Err(); err != nil {
		log.Fatal(scanner.Err())
	}
}
Task: Read a file line by line



C#: foreach (string readLine in File.ReadLines("FileName"))
  DoSomething(readLine);








Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line


C++: #include <fstream>
#include <string>
#include <iostream>

int main( int argc , char** argv ) {
   int linecount = 0 ;
   std::string line  ;
   std::ifstream infile( argv[ 1 ] ) ; 
   if ( infile ) {
      while ( getline( infile , line ) ) {
	 std::cout << linecount << ": " 
                   << line      << '\n' ;  
	 linecount++ ;
      }
   }
   infile.close( ) ;
   return 0 ;
}









Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line

C: 

#include <conio.h>
#include <stdio.h>

int main()
{
    int n1, n2, n3;

    printf( "\n   Introduzca el primer n%cmero (entero): ", 163 );
    scanf( "%d", &n1 );
    printf( "\n   Introduzca el segundo n%cmero (entero): ", 163 );
    scanf( "%d", &n2 );
    printf( "\n   Introduzca el tercer n%cmero (entero): ", 163 );
    scanf( "%d", &n3 );

    if ( n1 >= n2 && n1 >= n3 )
        printf( "\n   %d es el mayor.", n1 );
    else

        if ( n2 > n3 )
            printf( "\n   %d es el mayor.", n2 );
        else
            printf( "\n   %d es el mayor.", n3 );
 
    getch(); 

    return 0;
}










Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line





Java: import java.io.BufferedReader;
import java.io.FileReader;


public class ReadFileByLines {
    private static void processLine(int lineNo, String line) {
        
    }

    public static void main(String[] args) {
        for (String filename : args) {
            BufferedReader br = null;
            FileReader fr = null;
            try {
                fr = new FileReader(filename);
                br = new BufferedReader(fr);
                String line;
                int lineNo = 0;
                while ((line = br.readLine()) != null) {
                    processLine(++lineNo, line);
                }
            }
            catch (Exception x) {
                x.printStackTrace();
            }
            finally {
                if (fr != null) {
                    try {br.close();} catch (Exception ignoreMe) {}
                    try {fr.close();} catch (Exception ignoreMe) {}
                }
            }
        }
    }
}






Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line







Python: for line in lines open('input.txt'):
    print line




Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line








VB: $Include "Rapidq.inc"
dim file as qfilestream

if file.open("c:\A Test.txt", fmOpenRead) then
    while not File.eof
        print File.readline
    wend
else
    print "Cannot read file"
end if

input "Press enter to exit: ";a$



Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line






PHP: <?php
$file = fopen(__FILE__, 'r'); // read current file
while ($line = fgets($file)) {
    $line = rtrim($line);      // removes linebreaks and spaces at end
    echo strrev($line) . "\n"; // reverse line and upload it
}





Fortran:       INTEGER ENUFF		
      PARAMETER (ENUFF = 2468)	
      CHARACTER*(ENUFF) ALINE	
      CHARACTER*66 FNAME	
      INTEGER LINPR,IN		
      INTEGER L,N		
      LOGICAL EXIST		
      LINPR = 6			
      IN = 10			
      FNAME = "Read.for"	
      INQUIRE (FILE = FNAME, EXIST = EXIST)	
      IF (.NOT.EXIST) THEN		
        WRITE (LINPR,1) FNAME		
    1   FORMAT ("No sign of file ",A)	
        STOP "No file, no go."		
      END IF				
      OPEN (IN,FILE = FNAME, STATUS = "OLD", ACTION = "READ")	

      N = 0		
   10 READ (IN,11,END = 20) L,ALINE(1:MIN(L,ENUFF))	
   11 FORMAT (Q,A)		
      N = N + 1			
      IF (L.GT.ENUFF) WRITE (LINPR,12) N,L,ENUFF	
   12 FORMAT ("Record ",I0," has length ",I0,": my limit is ",I0)	
      WRITE (LINPR,13) N,ALINE(1:MIN(L,ENUFF))	
   13 FORMAT (I9,":",A)		
      GO TO 10			

   20 CLOSE (IN)	
      END
Task: Read a file line by line

C: 

#include <conio.h>
#include <stdio.h>

int main()
{
    int n1, n2, n3;

    printf( "\n   Introduzca el primer n%cmero (entero): ", 163 );
    scanf( "%d", &n1 );
    printf( "\n   Introduzca el segundo n%cmero (entero): ", 163 );
    scanf( "%d", &n2 );
    printf( "\n   Introduzca el tercer n%cmero (entero): ", 163 );
    scanf( "%d", &n3 );

    if ( n1 >= n2 && n1 >= n3 )
        printf( "\n   %d es el mayor.", n1 );
    else

        if ( n2 > n3 )
            printf( "\n   %d es el mayor.", n2 );
        else
            printf( "\n   %d es el mayor.", n3 );
 
    getch(); 

    return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .
Task: Read a file line by line



C#: foreach (string readLine in File.ReadLines("FileName"))
  DoSomething(readLine);







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .
Task: Read a file line by line


C++: #include <fstream>
#include <string>
#include <iostream>

int main( int argc , char** argv ) {
   int linecount = 0 ;
   std::string line  ;
   std::ifstream infile( argv[ 1 ] ) ; 
   if ( infile ) {
      while ( getline( infile , line ) ) {
	 std::cout << linecount << ": " 
                   << line      << '\n' ;  
	 linecount++ ;
      }
   }
   infile.close( ) ;
   return 0 ;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .
Task: Read a file line by line





Java: import java.io.BufferedReader;
import java.io.FileReader;


public class ReadFileByLines {
    private static void processLine(int lineNo, String line) {
        
    }

    public static void main(String[] args) {
        for (String filename : args) {
            BufferedReader br = null;
            FileReader fr = null;
            try {
                fr = new FileReader(filename);
                br = new BufferedReader(fr);
                String line;
                int lineNo = 0;
                while ((line = br.readLine()) != null) {
                    processLine(++lineNo, line);
                }
            }
            catch (Exception x) {
                x.printStackTrace();
            }
            finally {
                if (fr != null) {
                    try {br.close();} catch (Exception ignoreMe) {}
                    try {fr.close();} catch (Exception ignoreMe) {}
                }
            }
        }
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .
Task: Read a file line by line







Python: for line in lines open('input.txt'):
    print line



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .
Task: Read a file line by line








VB: $Include "Rapidq.inc"
dim file as qfilestream

if file.open("c:\A Test.txt", fmOpenRead) then
    while not File.eof
        print File.readline
    wend
else
    print "Cannot read file"
end if

input "Press enter to exit: ";a$


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. read-file-line-by-line.

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT input-file ASSIGN TO "input.txt"
               ORGANIZATION LINE SEQUENTIAL
               FILE STATUS input-file-status.

       DATA DIVISION.
       FILE SECTION.
       FD  input-file.
       01  input-record PIC X(256).

       WORKING-STORAGE SECTION.
       01  input-file-status PIC 99.
           88  file-is-ok    VALUE 0.
           88  end-of-file   VALUE 10.

       01  line-count        PIC 9(6).

       PROCEDURE DIVISION.
           OPEN INPUT input-file
           IF NOT file-is-ok
               DISPLAY "The file could not be opened."
               GOBACK
           END-IF

           PERFORM VARYING line-count FROM 1 BY 1 UNTIL end-of-file
               READ input-file
               DISPLAY line-count ": " FUNCTION TRIM(input-record)
           END-PERFORM

           CLOSE input-file

           GOBACK
           .