WeixiangYan/CodeTransOcean huggingface dataset:
Task: Ordered words




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
)

func main() {
    
    b, err := ioutil.ReadFile("unixdict.txt")
    if err != nil {
        fmt.Println(err)
        return
    }
    
    bss := bytes.Split(b, []byte{'\n'})

    
    var longest int
    var list [][]byte
    for _, bs := range bss {
        
        
        if len(bs) < longest {
            continue
        }
        
        var lastLetter byte
        for i := 0; ; i++ {
            if i == len(bs) {
                
                
                if len(bs) > longest {
                    longest = len(bs)
                    list = list[:0]
                }
                list = append(list, bs)
                break
            }
            
            b := bs[i]
            if b < 'a' || b > 'z' {
                continue 
            }
            if b < lastLetter {
                break 
            }
            
            lastLetter = b
        }
    }
    
    for _, bs := range list {
        fmt.Println(string(bs))
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.
Task: Arrays



C#:  int[] numbers = new int[10];









Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays

C:  char foo()
{
char array[5] = {3,6,9,12,15};
return array[2];
}











Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays


C++: #include <array>
#include <vector>


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


template <typename Array>
void demonstrate(Array& array)
{
  
  array[2] = "Three";  
                       
  array.at(1) = "Two"; 
                       
  
  
  std::reverse(begin(array), end(array));
  std::for_each(begin(array), end(array),
    [](typename Array::value_type const& element) 
    {
      std::cout << element << ' ';
    });
  
  std::cout << '\n';
}

int main()
{
  
  auto fixed_size_array = std::array<std::string, 3>{ "One", "Four", "Eight" };
  
  
  
  auto dynamic_array = std::vector<std::string>{ "One", "Four" };
  dynamic_array.push_back("Eight"); 
  
  
  demonstrate(fixed_size_array);
  demonstrate(dynamic_array);
}










Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays




Go: package main

import (
    "fmt"
)

func main() {
    
    
    
    var a [5]int

    
    
    fmt.Println("len(a) =", len(a))

    
    fmt.Println("a =", a)

    
    a[0] = 3
    fmt.Println("a =", a)

    
    fmt.Println("a[0] =", a[0])

    
    s := a[:4] 
    fmt.Println("s =", s)

    
    
    
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
    s = s[:5]
    fmt.Println("s =", s)

    
    a[0] = 22
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = append(s, 4, 5, 6)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    a[4] = -1
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = make([]int, 8)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
}








Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays





Java: Int[] literalArray = [1,2,3];
Int[] fixedLengthArray = new Int[10];
Int[] variableArray = new Int[];

assert literalArray.size == 3; 
Int n = literalArray[2];       
fixedLengthArray[4] = 12345;   

fixedLengthArray += 6789;  
variableArray    += 6789;  







Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays







Python: array = []

array.append(1)
array.append(3)

array[0] = 2

print array[0]





Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays








VB: Option Base {0|1}




Ada: procedure Array_Test is

   A, B : array (1..20) of Integer;

   
   C : array (-37..20) of integer

   
   
   type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
   type Activities is (Work, Fish);
   type Daily_Activities is array(Days) of Activities;
   This_Week : Daily_Activities := (Mon..Fri => Work, Others => Fish);

   
   type Fingers is range 1..4; 
   type Fingers_Extended_Type is array(fingers) of Boolean;
   Fingers_Extended : Fingers_Extended_Type;

   
   
   type Arr is array (Integer range <>) of Integer;
   Uninitialized : Arr (1 .. 10);
   Initialized_1 : Arr (1 .. 20) := (others => 1);
   Initialized_2 : Arr := (1 .. 30 => 2);
   Const         : constant Arr := (1 .. 10 => 1, 11 .. 20 => 2, 21 | 22 => 3);
   Centered      : Arr (-50..50) := (0 => 1, Others => 0);

   Result        : Integer
begin

   A := (others => 0);     
   B := (1 => 1, 2 => 1, 3 => 2, others => 0); 
                           
   A (1) := -1;            
   A (2..4) := B (1..3);   
   A (3..5) := (2, 4, -1); 
   A (3..5) := A (4..6);   
   
   Fingers_Extended'First := False; 
   Fingers_Extended'Last := False;  

end Array_Test;
Task: Arrays

C:  char foo()
{
char array[5] = {3,6,9,12,15};
return array[2];
}
Task: Arrays



C#:  int[] numbers = new int[10];
Task: Arrays


C++: #include <array>
#include <vector>


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


template <typename Array>
void demonstrate(Array& array)
{
  
  array[2] = "Three";  
                       
  array.at(1) = "Two"; 
                       
  
  
  std::reverse(begin(array), end(array));
  std::for_each(begin(array), end(array),
    [](typename Array::value_type const& element) 
    {
      std::cout << element << ' ';
    });
  
  std::cout << '\n';
}

int main()
{
  
  auto fixed_size_array = std::array<std::string, 3>{ "One", "Four", "Eight" };
  
  
  
  auto dynamic_array = std::vector<std::string>{ "One", "Four" };
  dynamic_array.push_back("Eight"); 
  
  
  demonstrate(fixed_size_array);
  demonstrate(dynamic_array);
}
Task: Arrays





Java: Int[] literalArray = [1,2,3];
Int[] fixedLengthArray = new Int[10];
Int[] variableArray = new Int[];

assert literalArray.size == 3; 
Int n = literalArray[2];       
fixedLengthArray[4] = 12345;   

fixedLengthArray += 6789;  
variableArray    += 6789;
Task: Arrays







Python: array = []

array.append(1)
array.append(3)

array[0] = 2

print(array[0])
Task: Arrays








VB: Option Base {0|1}
Task: Arrays




Go: package main

import (
    "fmt"
)

func main() {
    
    
    
    var a [5]int

    
    
    fmt.Println("len(a) =", len(a))

    
    fmt.Println("a =", a)

    
    a[0] = 3
    fmt.Println("a =", a)

    
    fmt.Println("a[0] =", a[0])

    
    s := a[:4] 
    fmt.Println("s =", s)

    
    
    
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
    s = s[:5]
    fmt.Println("s =", s)

    
    a[0] = 22
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = append(s, 4, 5, 6)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    a[4] = -1
    fmt.Println("a =", a)
    fmt.Println("s =", s)

    
    s = make([]int, 8)
    fmt.Println("s =", s)
    fmt.Println("len(s) =", len(s), " cap(s) =", cap(s))

    
    
}
Task: Arrays


C++: #include <array>
#include <vector>


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


template <typename Array>
void demonstrate(Array& array)
{
  
  array[2] = "Three";  
                       
  array.at(1) = "Two"; 
                       
  
  
  std::reverse(begin(array), end(array));
  std::for_each(begin(array), end(array),
    [](typename Array::value_type const& element) 
    {
      std::cout << element << ' ';
    });
  
  std::cout << '\n';
}

int main()
{
  
  auto fixed_size_array = std::array<std::string, 3>{ "One", "Four", "Eight" };
  
  
  
  auto dynamic_array = std::vector<std::string>{ "One", "Four" };
  dynamic_array.push_back("Eight"); 
  
  
  demonstrate(fixed_size_array);
  demonstrate(dynamic_array);
}









Fortran: integer a (10)
Task: Arrays





Java: Int[] literalArray = [1,2,3];
Int[] fixedLengthArray = new Int[10];
Int[] variableArray = new Int[];

assert literalArray.size == 3; 
Int n = literalArray[2];       
fixedLengthArray[4] = 12345;   

fixedLengthArray += 6789;  
variableArray    += 6789;  






Fortran: integer a (10)
Task: Arrays







Python: array = []

array.append(1)
array.append(3)

array[0] = 2

print array[0]




Fortran: integer a (10)
Task: Arrays






PHP: $NumberArray = array(0, 1, 2, 3, 4, 5, 6);
$LetterArray = array("a", "b", "c", "d", "e", "f");
$simpleForm = ['apple', 'orange'];





Fortran: integer a (10)
Task: Arrays

C:  char foo()
{
char array[5] = {3,6,9,12,15};
return array[2];
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays



C#:  int[] numbers = new int[10];







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays


C++: #include <array>
#include <vector>


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


template <typename Array>
void demonstrate(Array& array)
{
  
  array[2] = "Three";  
                       
  array.at(1) = "Two"; 
                       
  
  
  std::reverse(begin(array), end(array));
  std::for_each(begin(array), end(array),
    [](typename Array::value_type const& element) 
    {
      std::cout << element << ' ';
    });
  
  std::cout << '\n';
}

int main()
{
  
  auto fixed_size_array = std::array<std::string, 3>{ "One", "Four", "Eight" };
  
  
  
  auto dynamic_array = std::vector<std::string>{ "One", "Four" };
  dynamic_array.push_back("Eight"); 
  
  
  demonstrate(fixed_size_array);
  demonstrate(dynamic_array);
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays





Java: Int[] literalArray = [1,2,3];
Int[] fixedLengthArray = new Int[10];
Int[] variableArray = new Int[];

assert literalArray.size == 3; 
Int n = literalArray[2];       
fixedLengthArray[4] = 12345;   

fixedLengthArray += 6789;  
variableArray    += 6789;  





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .
Task: Arrays







Python: array = []

array.append(1)
array.append(3)

array[0] = 2

print(array[0])



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. arrays.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  fixed-length-table.
           03  fixed-table-elt      PIC X OCCURS 5 TIMES.

       01  table-length             PIC 9(5) VALUE 1.
       01  variable-length-table.
           03  variable-table-elt   PIC X OCCURS 1 TO 5 TIMES
               DEPENDING ON table-length.

       01  initial-value-area.
           03  initial-values.
               05  FILLER           PIC X(10) VALUE "One".
               05  FILLER           PIC X(10) VALUE "Two".
               05  FILLER           PIC X(10) VALUE "Three".
           03 initial-value-table REDEFINES initial-values.
              05  initial-table-elt PIC X(10) OCCURS 3 TIMES.

       01  indexed-table.
           03  indexed-elt          PIC X OCCURS 5 TIMES
               INDEXED BY table-index.

       PROCEDURE DIVISION.
           
           MOVE "12345" TO fixed-length-table
           
           
           MOVE 1 TO table-index
           MOVE "1" TO indexed-elt (table-index)

           
           ADD 1 TO table-length
           MOVE "1" TO variable-table-elt (2)

           GOBACK
           .