WeixiangYan/CodeTransOcean huggingface dataset:
Task: Van der Corput sequence


C++: #include <cmath>
#include <iostream>

double vdc(int n, double base = 2)
{
    double vdc = 0, denom = 1;
    while (n)
    {
        vdc += fmod(n, base) / (denom *= base);
        n /= base; 
    }
    return vdc;
}

int main() 
{
    for (double base = 2; base < 6; ++base)
    {
        std::cout << "Base " << base << "\n";
        for (int n = 0; n < 10; ++n)
        {
            std::cout << vdc(n, base) << " ";
        }
        std::cout << "\n\n";
    }
}










Ada: with Ada.Text_IO;

procedure Main is
   package Float_IO is new Ada.Text_IO.Float_IO (Float);
   function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
      Value    : Natural  := N;
      Result   : Float    := 0.0;
      Exponent : Positive := 1;
   begin
      while Value > 0 loop
         Result   := Result +
                     Float (Value mod Base) / Float (Base ** Exponent);
         Value    := Value / Base;
         Exponent := Exponent + 1;
      end loop;
      return Result;
   end Van_Der_Corput;
begin
   for Base in 2 .. 5 loop
      Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
      for N in 1 .. 10 loop
         Ada.Text_IO.Put (' ');
         Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Main;
Task: Van der Corput sequence




Go: package main

import "fmt"

func v2(n uint) (r float64) {
    p := .5
    for n > 0 {
        if n&1 == 1 {
            r += p
        }
        p *= .5
        n >>= 1
    }
    return
}

func newV(base uint) func(uint) float64 {
    invb := 1 / float64(base)
    return func(n uint) (r float64) {
        p := invb
        for n > 0 {
            r += p * float64(n%base)
            p *= invb
            n /= base
        }
        return
    }
}

func main() {
    fmt.Println("Base 2:")
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v2(i))
    }
    fmt.Println("Base 3:")
    v3 := newV(3)
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v3(i))
    }
}








Ada: with Ada.Text_IO;

procedure Main is
   package Float_IO is new Ada.Text_IO.Float_IO (Float);
   function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
      Value    : Natural  := N;
      Result   : Float    := 0.0;
      Exponent : Positive := 1;
   begin
      while Value > 0 loop
         Result   := Result +
                     Float (Value mod Base) / Float (Base ** Exponent);
         Value    := Value / Base;
         Exponent := Exponent + 1;
      end loop;
      return Result;
   end Van_Der_Corput;
begin
   for Base in 2 .. 5 loop
      Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
      for N in 1 .. 10 loop
         Ada.Text_IO.Put (' ');
         Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Main;
Task: Van der Corput sequence





Java: public class VanDerCorput{
	public static double vdc(int n){
		double vdc = 0;
		int denom = 1;
		while(n != 0){
			vdc += n % 2.0 / (denom *= 2);
			n /= 2;
		}
		return vdc;
	}
	
	public static void main(String[] args){
		for(int i = 0; i <= 10; i++){
			System.out.println(vdc(i));
		}
	}
}







Ada: with Ada.Text_IO;

procedure Main is
   package Float_IO is new Ada.Text_IO.Float_IO (Float);
   function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
      Value    : Natural  := N;
      Result   : Float    := 0.0;
      Exponent : Positive := 1;
   begin
      while Value > 0 loop
         Result   := Result +
                     Float (Value mod Base) / Float (Base ** Exponent);
         Value    := Value / Base;
         Exponent := Exponent + 1;
      end loop;
      return Result;
   end Van_Der_Corput;
begin
   for Base in 2 .. 5 loop
      Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
      for N in 1 .. 10 loop
         Ada.Text_IO.Put (' ');
         Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Main;
Task: Van der Corput sequence







Python: >>> def base10change(n, base):
	digits = []
	while n:
		n,remainder = divmod(n, base)
		digits.insert(0, remainder)
	return digits

>>> base10change(11, 2)
[1, 0, 1, 1]





Ada: with Ada.Text_IO;

procedure Main is
   package Float_IO is new Ada.Text_IO.Float_IO (Float);
   function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
      Value    : Natural  := N;
      Result   : Float    := 0.0;
      Exponent : Positive := 1;
   begin
      while Value > 0 loop
         Result   := Result +
                     Float (Value mod Base) / Float (Base ** Exponent);
         Value    := Value / Base;
         Exponent := Exponent + 1;
      end loop;
      return Result;
   end Van_Der_Corput;
begin
   for Base in 2 .. 5 loop
      Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
      for N in 1 .. 10 loop
         Ada.Text_IO.Put (' ');
         Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Main;
Task: Van der Corput sequence








VB: Private Function vdc(ByVal n As Integer, BASE As Variant) As Variant
    Dim res As String
    Dim digit As Integer, g As Integer, denom As Integer
    denom = 1
    Do While n
        denom = denom * BASE
        digit = n Mod BASE
        n = n \ BASE
        res = res & CStr(digit) 
    Loop
    vdc = IIf(Len(res) = 0, "0", "0." & res)
End Function
 
Public Sub show_vdc()
    Dim v As Variant, j As Integer
    For i = 2 To 5
        Debug.Print "Base "; i; ": ";
        For j = 0 To 9
            v = vdc(j, i)
            Debug.Print v; " ";
        Next j
        Debug.Print
    Next i
End Sub




Ada: with Ada.Text_IO;

procedure Main is
   package Float_IO is new Ada.Text_IO.Float_IO (Float);
   function Van_Der_Corput (N : Natural; Base : Positive := 2) return Float is
      Value    : Natural  := N;
      Result   : Float    := 0.0;
      Exponent : Positive := 1;
   begin
      while Value > 0 loop
         Result   := Result +
                     Float (Value mod Base) / Float (Base ** Exponent);
         Value    := Value / Base;
         Exponent := Exponent + 1;
      end loop;
      return Result;
   end Van_Der_Corput;
begin
   for Base in 2 .. 5 loop
      Ada.Text_IO.Put ("Base" & Integer'Image (Base) & ":");
      for N in 1 .. 10 loop
         Ada.Text_IO.Put (' ');
         Float_IO.Put (Item => Van_Der_Corput (N, Base), Exp => 0);
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Main;
Task: Van der Corput sequence

C: #include <stdio.h>

void vc(int n, int base, int *num, int *denom)
{
        int p = 0, q = 1;

        while (n) {
                p = p * base + (n % base);
                q *= base;
                n /= base;
        }

        *num = p;  
        *denom = q;

        while (p) { n = p; p = q % p; q = n; }
        *num /= q;
        *denom /= q;
}

int main()
{
        int d, n, i, b;
        for (b = 2; b < 6; b++) {
                printf("base %d:", b);
                for (i = 0; i < 10; i++) {
                        vc(i, b, &n, &d);
                        if (n) printf("  %d/%d", n, d);
                        else   printf("  0");
                }
                printf("\n");
        }

        return 0;
}
Task: Van der Corput sequence



C#: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VanDerCorput
{
    
    
    
    
    
    
    
    
    
    
    
    
    public class VanDerCorputSequence: IEnumerable<Tuple<long,long>>
    {
        
        
        
        public int Base { get; private set; }

        
        
        
        public long Count { get; private set; }

        
        
        
        
        
        public VanDerCorputSequence(int iBase, long count = long.MaxValue) {
            if (iBase < 2)
                throw new ArgumentOutOfRangeException("iBase", "must be two or greater, not the given value of " + iBase);
            Base = iBase;
            Count = count;
        }

        
        
        
        
        
        
        public Tuple<long,long> Compute(long n)
        {
            long p = 0, q = 1;
            long numerator, denominator;
            while (n != 0)
            {
                p = p * Base + (n % Base);
                q *= Base;
                n /= Base;
            }
            numerator = p;
            denominator = q;
            while (p != 0) 
            { 
                n = p; 
                p = q % p; 
                q = n; 
            }
            numerator /= q;
            denominator /= q;
            return new Tuple<long,long>(numerator, denominator);
        }

        
        
        
        
        
        
        public static Tuple<long, long> Compute(int iBase, long n)
        {
            var seq = new VanDerCorputSequence(iBase);
            return seq.Compute(n);
        }

        
        
        
        
        
        public IEnumerator<Tuple<long, long>> GetEnumerator()
        {
            long iSequenceIndex = 0L;
            while (iSequenceIndex < Count)
            {
                yield return Compute(iSequenceIndex);
                iSequenceIndex++;
            }
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            TestBasesTwoThroughFive();

            Console.WriteLine("Type return to continue...");
            Console.ReadLine();
        }

        static void TestBasesTwoThroughFive()
        {
            foreach (var seq in Enumerable.Range(2, 5).Select(x => new VanDerCorputSequence(x, 10))) 
            {
                Console.Write("base " + seq.Base + ":");
                foreach(var vc in seq) 
                    Console.Write(" " + vc.Item1 + "/" + vc.Item2);
                Console.WriteLine();
            }
        }
    }
}
Task: Van der Corput sequence


C++: #include <cmath>
#include <iostream>

double vdc(int n, double base = 2)
{
    double vdc = 0, denom = 1;
    while (n)
    {
        vdc += fmod(n, base) / (denom *= base);
        n /= base; 
    }
    return vdc;
}

int main() 
{
    for (double base = 2; base < 6; ++base)
    {
        std::cout << "Base " << base << "\n";
        for (int n = 0; n < 10; ++n)
        {
            std::cout << vdc(n, base) << " ";
        }
        std::cout << "\n\n";
    }
}
Task: Van der Corput sequence





Java: public class VanDerCorput{
	public static double vdc(int n){
		double vdc = 0;
		int denom = 1;
		while(n != 0){
			vdc += n % 2.0 / (denom *= 2);
			n /= 2;
		}
		return vdc;
	}
	
	public static void main(String[] args){
		for(int i = 0; i <= 10; i++){
			System.out.println(vdc(i));
		}
	}
}
Task: Van der Corput sequence







Python: >>> def base10change(n, base):
	digits = []
	while n:
		n,remainder = divmod(n, base)
		digits.insert(0, remainder)
	return digits

>>> base10change(11, 2)
[1, 0, 1, 1]
Task: Van der Corput sequence








VB: Private Function vdc(ByVal n As Integer, BASE As Variant) As Variant
    Dim res As String
    Dim digit As Integer, g As Integer, denom As Integer
    denom = 1
    Do While n
        denom = denom * BASE
        digit = n Mod BASE
        n = n \ BASE
        res = res & CStr(digit) 
    Loop
    vdc = IIf(Len(res) = 0, "0", "0." & res)
End Function
 
Public Sub show_vdc()
    Dim v As Variant, j As Integer
    For i = 2 To 5
        Debug.Print "Base "; i; ": ";
        For j = 0 To 9
            v = vdc(j, i)
            Debug.Print v; " ";
        Next j
        Debug.Print
    Next i
End Sub
Task: Van der Corput sequence




Go: package main

import "fmt"

func v2(n uint) (r float64) {
    p := .5
    for n > 0 {
        if n&1 == 1 {
            r += p
        }
        p *= .5
        n >>= 1
    }
    return
}

func newV(base uint) func(uint) float64 {
    invb := 1 / float64(base)
    return func(n uint) (r float64) {
        p := invb
        for n > 0 {
            r += p * float64(n%base)
            p *= invb
            n /= base
        }
        return
    }
}

func main() {
    fmt.Println("Base 2:")
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v2(i))
    }
    fmt.Println("Base 3:")
    v3 := newV(3)
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v3(i))
    }
}
Task: Van der Corput sequence


C++: #include <cmath>
#include <iostream>

double vdc(int n, double base = 2)
{
    double vdc = 0, denom = 1;
    while (n)
    {
        vdc += fmod(n, base) / (denom *= base);
        n /= base; 
    }
    return vdc;
}

int main() 
{
    for (double base = 2; base < 6; ++base)
    {
        std::cout << "Base " << base << "\n";
        for (int n = 0; n < 10; ++n)
        {
            std::cout << vdc(n, base) << " ";
        }
        std::cout << "\n\n";
    }
}









Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Van der Corput sequence

C: #include <stdio.h>

void vc(int n, int base, int *num, int *denom)
{
        int p = 0, q = 1;

        while (n) {
                p = p * base + (n % base);
                q *= base;
                n /= base;
        }

        *num = p;  
        *denom = q;

        while (p) { n = p; p = q % p; q = n; }
        *num /= q;
        *denom /= q;
}

int main()
{
        int d, n, i, b;
        for (b = 2; b < 6; b++) {
                printf("base %d:", b);
                for (i = 0; i < 10; i++) {
                        vc(i, b, &n, &d);
                        if (n) printf("  %d/%d", n, d);
                        else   printf("  0");
                }
                printf("\n");
        }

        return 0;
}










Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Van der Corput sequence




Go: package main

import "fmt"

func v2(n uint) (r float64) {
    p := .5
    for n > 0 {
        if n&1 == 1 {
            r += p
        }
        p *= .5
        n >>= 1
    }
    return
}

func newV(base uint) func(uint) float64 {
    invb := 1 / float64(base)
    return func(n uint) (r float64) {
        p := invb
        for n > 0 {
            r += p * float64(n%base)
            p *= invb
            n /= base
        }
        return
    }
}

func main() {
    fmt.Println("Base 2:")
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v2(i))
    }
    fmt.Println("Base 3:")
    v3 := newV(3)
    for i := uint(0); i < 10; i++ {
        fmt.Println(i, v3(i))
    }
}







Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Van der Corput sequence





Java: public class VanDerCorput{
	public static double vdc(int n){
		double vdc = 0;
		int denom = 1;
		while(n != 0){
			vdc += n % 2.0 / (denom *= 2);
			n /= 2;
		}
		return vdc;
	}
	
	public static void main(String[] args){
		for(int i = 0; i <= 10; i++){
			System.out.println(vdc(i));
		}
	}
}






Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Van der Corput sequence







Python: >>> def base10change(n, base):
	digits = []
	while n:
		n,remainder = divmod(n, base)
		digits.insert(0, remainder)
	return digits

>>> base10change(11, 2)
[1, 0, 1, 1]




Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Van der Corput sequence








VB: Private Function vdc(ByVal n As Integer, BASE As Variant) As Variant
    Dim res As String
    Dim digit As Integer, g As Integer, denom As Integer
    denom = 1
    Do While n
        denom = denom * BASE
        digit = n Mod BASE
        n = n \ BASE
        res = res & CStr(digit) 
    Loop
    vdc = IIf(Len(res) = 0, "0", "0." & res)
End Function
 
Public Sub show_vdc()
    Dim v As Variant, j As Integer
    For i = 2 To 5
        Debug.Print "Base "; i; ": ";
        For j = 0 To 9
            v = vdc(j, i)
            Debug.Print v; " ";
        Next j
        Debug.Print
    Next i
End Sub



Fortran:       FUNCTION VDC(N,BASE)	
Converts 1234 in decimal to 4321 in V, and P = 10000.
       INTEGER N	
       INTEGER BASE	
       INTEGER I	
       INTEGER P	
       INTEGER V	
        P = 1		
        V = 0		
        I = N		
        DO WHILE (I .NE. 0)	
          V = V*BASE + MOD(I,BASE)	
          I = I/BASE			
          P = P*BASE			
        END DO			
        VDC = V/FLOAT(P)	
      END FUNCTION VDC	

      PROGRAM POKE
      INTEGER FIRST,LAST	
      PARAMETER (FIRST = 0,LAST = 9)	
      INTEGER I,BASE		
      REAL VDC			

      WRITE (6,1) FIRST,LAST,(I, I = FIRST,LAST)	
    1 FORMAT ("Calculates values ",I0," to ",I0," of the ",
     1 "Van der Corput sequence, in various bases."/
     2 "Base",666I9)

      DO BASE = 2,13	
        WRITE (6,2) BASE,(VDC(I,BASE), I = FIRST,LAST)	
    2   FORMAT (I4,666F9.6)	
      END DO		

      END
Task: Loops_Nested



C#: using System;

class Program {
    static void Main(string[] args) {
        int[,] a = new int[10, 10];
        Random r = new Random();

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                a[i, j] = r.Next(0, 21) + 1;
            }
        }
        
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                Console.Write(" {0}", a[i, j]);
                if (a[i, j] == 20) {
                    goto Done;
                }
            }
            Console.WriteLine();
        }
    Done:
        Console.WriteLine();
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;

procedure Test_Loop_Nested is
   type Value_Type is range 1..20;
   package Random_Values is new Ada.Numerics.Discrete_Random (Value_Type);
   use Random_Values;
   Dice : Generator;
   A : array (1..10, 1..10) of Value_Type :=
          (others => (others => Random (Dice)));
begin

Outer :
   for I in A'Range (1) loop
      for J in A'Range (2) loop
         Put (Value_Type'Image (A (I, J)));
         exit Outer when A (I, J) = 20;
      end loop;
      New_Line;
   end loop Outer;
end Test_Loop_Nested;
Task: Loops_Nested

C: #include <stdlib.h>
#include <time.h>
#include <stdio.h>

int main() {
    int a[10][10], i, j;

    srand(time(NULL));
    for (i = 0; i < 10; i++)
        for (j = 0; j < 10; j++)
            a[i][j] = rand() % 20 + 1;

    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            printf(" %d", a[i][j]);
            if (a[i][j] == 20)
                goto Done;
        }
        printf("\n");
    }
Done:
    printf("\n");
    return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;

procedure Test_Loop_Nested is
   type Value_Type is range 1..20;
   package Random_Values is new Ada.Numerics.Discrete_Random (Value_Type);
   use Random_Values;
   Dice : Generator;
   A : array (1..10, 1..10) of Value_Type :=
          (others => (others => Random (Dice)));
begin

Outer :
   for I in A'Range (1) loop
      for J in A'Range (2) loop
         Put (Value_Type'Image (A (I, J)));
         exit Outer when A (I, J) = 20;
      end loop;
      New_Line;
   end loop Outer;
end Test_Loop_Nested;
Task: Loops_Nested


C++: #include<cstdlib>
#include<ctime>
#include<iostream>

using namespace std;
int main()
{
    int arr[10][10];
    srand(time(NULL));
    for(auto& row: arr)
        for(auto& col: row)
            col = rand() % 20 + 1;

    ([&](){
       for(auto& row : arr)
           for(auto& col: row)
           {
               cout << col << endl;
               if(col == 20)return;
           }
    })();
    return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;

procedure Test_Loop_Nested is
   type Value_Type is range 1..20;
   package Random_Values is new Ada.Numerics.Discrete_Random (Value_Type);
   use Random_Values;
   Dice : Generator;
   A : array (1..10, 1..10) of Value_Type :=
          (others => (others => Random (Dice)));
begin

Outer :
   for I in A'Range (1) loop
      for J in A'Range (2) loop
         Put (Value_Type'Image (A (I, J)));
         exit Outer when A (I, J) = 20;
      end loop;
      New_Line;
   end loop Outer;
end Test_Loop_Nested;