WeixiangYan/CodeTransOcean huggingface dataset:
Task: Keyboard input_Keypress check





Java: import java.awt.event.*;
import javax.swing.*;

public class Test extends JFrame {

    Test() {
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                int keyCode = e.getKeyCode();
                System.out.println(keyCode);
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            Test f = new Test();
            f.setFocusable(true);
            f.setVisible(true);
        });
    }
}



Python: 

from __future__ import absolute_import, division, unicode_literals, print_function

import tty, termios
import sys
if sys.version_info.major < 3:
    import thread as _thread
else:
    import _thread
import time


try:
    from msvcrt import getch  
except ImportError:
    def getch():   
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

def keypress():
    global char
    char = getch()

def main():
    global char
    char = None
    _thread.start_new_thread(keypress, ())

    while True:
        if char is not None:
            try:
                print("Key pressed is " + char.decode('utf-8'))
            except UnicodeDecodeError:
                print("character can not be decoded, sorry!")
                char = None
            _thread.start_new_thread(keypress, ())
            if char == 'q' or char == '\x1b':  
                exit()
            char = None
        print("Program is running")
        time.sleep(1)

if __name__ == "__main__":
    main()
Task: Arithmetic-geometric mean

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

double agm( double a, double g ) {
   
   double iota = 1.0E-16;
   double a1, g1;
   
   if( a*g < 0.0 ) {
      printf( "arithmetic-geometric mean undefined when x*y<0\n" );
      exit(1);
   }

   while( fabs(a-g)>iota ) {
      a1 = (a + g) / 2.0;
      g1 = sqrt(a * g);

      a = a1;
      g = g1;
   }
   
   return a;
}

int main( void ) {
   double x, y;
   printf( "Enter two numbers: " );
   scanf( "%lf%lf", &x, &y );
   printf( "The arithmetic-geometric mean is %lf\n", agm(x, y) );
   return 0;
}


C++: 

#include "gmp.h"

void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
	mpf_add (out1, in1, in2);
	mpf_div_ui (out1, out1, 2);
	mpf_mul (out2, in1, in2);
	mpf_sqrt (out2, out2);
}

int main (void) {
	mpf_set_default_prec (65568);
	mpf_t x0, y0, resA, resB;

	mpf_init_set_ui (y0, 1);
	mpf_init_set_d (x0, 0.5);
	mpf_sqrt (x0, x0);
	mpf_init (resA);
	mpf_init (resB);

	for(int i=0; i<7; i++){
		agm(x0, y0, resA, resB);
		agm(resA, resB, x0, y0);
	}
	gmp_printf ("%.20000Ff\n", x0);
	gmp_printf ("%.20000Ff\n\n", y0);

	return 0;
}
Task: Arithmetic-geometric mean


C++: 

#include "gmp.h"

void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
	mpf_add (out1, in1, in2);
	mpf_div_ui (out1, out1, 2);
	mpf_mul (out2, in1, in2);
	mpf_sqrt (out2, out2);
}

int main (void) {
	mpf_set_default_prec (65568);
	mpf_t x0, y0, resA, resB;

	mpf_init_set_ui (y0, 1);
	mpf_init_set_d (x0, 0.5);
	mpf_sqrt (x0, x0);
	mpf_init (resA);
	mpf_init (resB);

	for(int i=0; i<7; i++){
		agm(x0, y0, resA, resB);
		agm(resA, resB, x0, y0);
	}
	gmp_printf ("%.20000Ff\n", x0);
	gmp_printf ("%.20000Ff\n\n", y0);

	return 0;
}






Python: from math import sqrt

def agm(a0, g0, tolerance=1e-10):
    
    an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
    while abs(an - gn) > tolerance:
        an, gn = (an + gn) / 2.0, sqrt(an * gn)
    return an

print agm(1, 1 / sqrt(2))
Task: Arithmetic-geometric mean


C++: 

#include "gmp.h"

void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
	mpf_add (out1, in1, in2);
	mpf_div_ui (out1, out1, 2);
	mpf_mul (out2, in1, in2);
	mpf_sqrt (out2, out2);
}

int main (void) {
	mpf_set_default_prec (65568);
	mpf_t x0, y0, resA, resB;

	mpf_init_set_ui (y0, 1);
	mpf_init_set_d (x0, 0.5);
	mpf_sqrt (x0, x0);
	mpf_init (resA);
	mpf_init (resB);

	for(int i=0; i<7; i++){
		agm(x0, y0, resA, resB);
		agm(resA, resB, x0, y0);
	}
	gmp_printf ("%.20000Ff\n", x0);
	gmp_printf ("%.20000Ff\n\n", y0);

	return 0;
}







VB: Private Function agm(a As Double, g As Double, Optional tolerance As Double = 0.000000000000001) As Double
    Do While Abs(a - g) > tolerance
        tmp = a
        a = (a + g) / 2
        g = Sqr(tmp * g)
        Debug.Print a
    Loop
    agm = a
End Function
Public Sub main()
    Debug.Print agm(1, 1 / Sqr(2))
End Sub
Task: Arithmetic-geometric mean



C#: namespace RosettaCode.ArithmeticGeometricMean
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;

    internal static class Program
    {
        private static double ArithmeticGeometricMean(double number,
                                                      double otherNumber,
                                                      IEqualityComparer<double>
                                                          comparer)
        {
            return comparer.Equals(number, otherNumber)
                       ? number
                       : ArithmeticGeometricMean(
                           ArithmeticMean(number, otherNumber),
                           GeometricMean(number, otherNumber), comparer);
        }

        private static double ArithmeticMean(double number, double otherNumber)
        {
            return 0.5 * (number + otherNumber);
        }

        private static double GeometricMean(double number, double otherNumber)
        {
            return Math.Sqrt(number * otherNumber);
        }

        private static void Main()
        {
            Console.WriteLine(
                ArithmeticGeometricMean(1, 0.5 * Math.Sqrt(2),
                                        new RelativeDifferenceComparer(1e-5)).
                    ToString(CultureInfo.InvariantCulture));
        }

        private class RelativeDifferenceComparer : IEqualityComparer<double>
        {
            private readonly double _maximumRelativeDifference;

            internal RelativeDifferenceComparer(double maximumRelativeDifference)
            {
                _maximumRelativeDifference = maximumRelativeDifference;
            }

            public bool Equals(double number, double otherNumber)
            {
                return RelativeDifference(number, otherNumber) <=
                       _maximumRelativeDifference;
            }

            public int GetHashCode(double number)
            {
                return number.GetHashCode();
            }

            private static double RelativeDifference(double number,
                                                     double otherNumber)
            {
                return AbsoluteDifference(number, otherNumber) /
                       Norm(number, otherNumber);
            }

            private static double AbsoluteDifference(double number,
                                                     double otherNumber)
            {
                return Math.Abs(number - otherNumber);
            }

            private static double Norm(double number, double otherNumber)
            {
                return 0.5 * (Math.Abs(number) + Math.Abs(otherNumber));
            }
        }
    }
}





Python: from math import sqrt

def agm(a0, g0, tolerance=1e-10):
    
    an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
    while abs(an - gn) > tolerance:
        an, gn = (an + gn) / 2.0, sqrt(an * gn)
    return an

print agm(1, 1 / sqrt(2))
Task: Arithmetic-geometric mean



C#: namespace RosettaCode.ArithmeticGeometricMean
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;

    internal static class Program
    {
        private static double ArithmeticGeometricMean(double number,
                                                      double otherNumber,
                                                      IEqualityComparer<double>
                                                          comparer)
        {
            return comparer.Equals(number, otherNumber)
                       ? number
                       : ArithmeticGeometricMean(
                           ArithmeticMean(number, otherNumber),
                           GeometricMean(number, otherNumber), comparer);
        }

        private static double ArithmeticMean(double number, double otherNumber)
        {
            return 0.5 * (number + otherNumber);
        }

        private static double GeometricMean(double number, double otherNumber)
        {
            return Math.Sqrt(number * otherNumber);
        }

        private static void Main()
        {
            Console.WriteLine(
                ArithmeticGeometricMean(1, 0.5 * Math.Sqrt(2),
                                        new RelativeDifferenceComparer(1e-5)).
                    ToString(CultureInfo.InvariantCulture));
        }

        private class RelativeDifferenceComparer : IEqualityComparer<double>
        {
            private readonly double _maximumRelativeDifference;

            internal RelativeDifferenceComparer(double maximumRelativeDifference)
            {
                _maximumRelativeDifference = maximumRelativeDifference;
            }

            public bool Equals(double number, double otherNumber)
            {
                return RelativeDifference(number, otherNumber) <=
                       _maximumRelativeDifference;
            }

            public int GetHashCode(double number)
            {
                return number.GetHashCode();
            }

            private static double RelativeDifference(double number,
                                                     double otherNumber)
            {
                return AbsoluteDifference(number, otherNumber) /
                       Norm(number, otherNumber);
            }

            private static double AbsoluteDifference(double number,
                                                     double otherNumber)
            {
                return Math.Abs(number - otherNumber);
            }

            private static double Norm(double number, double otherNumber)
            {
                return 0.5 * (Math.Abs(number) + Math.Abs(otherNumber));
            }
        }
    }
}






VB: Private Function agm(a As Double, g As Double, Optional tolerance As Double = 0.000000000000001) As Double
    Do While Abs(a - g) > tolerance
        tmp = a
        a = (a + g) / 2
        g = Sqr(tmp * g)
        Debug.Print a
    Loop
    agm = a
End Function
Public Sub main()
    Debug.Print agm(1, 1 / Sqr(2))
End Sub
Task: Arithmetic-geometric mean







Python: from math import sqrt

def agm(a0, g0, tolerance=1e-10):
    
    an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
    while abs(an - gn) > tolerance:
        an, gn = (an + gn) / 2.0, sqrt(an * gn)
    return an

print agm(1, 1 / sqrt(2))


VB: Private Function agm(a As Double, g As Double, Optional tolerance As Double = 0.000000000000001) As Double
    Do While Abs(a - g) > tolerance
        tmp = a
        a = (a + g) / 2
        g = Sqr(tmp * g)
        Debug.Print a
    Loop
    agm = a
End Function
Public Sub main()
    Debug.Print agm(1, 1 / Sqr(2))
End Sub
Task: Arithmetic-geometric mean

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

double agm( double a, double g ) {
   
   double iota = 1.0E-16;
   double a1, g1;
   
   if( a*g < 0.0 ) {
      printf( "arithmetic-geometric mean undefined when x*y<0\n" );
      exit(1);
   }

   while( fabs(a-g)>iota ) {
      a1 = (a + g) / 2.0;
      g1 = sqrt(a * g);

      a = a1;
      g = g1;
   }
   
   return a;
}

int main( void ) {
   double x, y;
   printf( "Enter two numbers: " );
   scanf( "%lf%lf", &x, &y );
   printf( "The arithmetic-geometric mean is %lf\n", agm(x, y) );
   return 0;
}







Python: from math import sqrt

def agm(a0, g0, tolerance=1e-10):
    
    an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
    while abs(an - gn) > tolerance:
        an, gn = (an + gn) / 2.0, sqrt(an * gn)
    return an

print agm(1, 1 / sqrt(2))
Task: Arithmetic-geometric mean

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

double agm( double a, double g ) {
   
   double iota = 1.0E-16;
   double a1, g1;
   
   if( a*g < 0.0 ) {
      printf( "arithmetic-geometric mean undefined when x*y<0\n" );
      exit(1);
   }

   while( fabs(a-g)>iota ) {
      a1 = (a + g) / 2.0;
      g1 = sqrt(a * g);

      a = a1;
      g = g1;
   }
   
   return a;
}

int main( void ) {
   double x, y;
   printf( "Enter two numbers: " );
   scanf( "%lf%lf", &x, &y );
   printf( "The arithmetic-geometric mean is %lf\n", agm(x, y) );
   return 0;
}








VB: Private Function agm(a As Double, g As Double, Optional tolerance As Double = 0.000000000000001) As Double
    Do While Abs(a - g) > tolerance
        tmp = a
        a = (a + g) / 2
        g = Sqr(tmp * g)
        Debug.Print a
    Loop
    agm = a
End Function
Public Sub main()
    Debug.Print agm(1, 1 / Sqr(2))
End Sub
Task: Arithmetic-geometric mean

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

double agm( double a, double g ) {
   
   double iota = 1.0E-16;
   double a1, g1;
   
   if( a*g < 0.0 ) {
      printf( "arithmetic-geometric mean undefined when x*y<0\n" );
      exit(1);
   }

   while( fabs(a-g)>iota ) {
      a1 = (a + g) / 2.0;
      g1 = sqrt(a * g);

      a = a1;
      g = g1;
   }
   
   return a;
}

int main( void ) {
   double x, y;
   printf( "Enter two numbers: " );
   scanf( "%lf%lf", &x, &y );
   printf( "The arithmetic-geometric mean is %lf\n", agm(x, y) );
   return 0;
}






PHP: define('PRECISION', 13);

function agm($a0, $g0, $tolerance = 1e-10)                                                                                                    
{



    $limit = number_format($tolerance, PRECISION, '.', '');
    $an    = $a0;
    $gn    = $g0;
    do {
        list($an, $gn) = array(
            bcdiv(bcadd($an, $gn), 2), 
            bcsqrt(bcmul($an, $gn)),
        );  
    } while (bccomp(bcsub($an, $gn), $limit) > 0); 

    return $an;
}

bcscale(PRECISION);
echo agm(1, 1 / bcsqrt(2));
Task: Arithmetic-geometric mean


C++: 

#include "gmp.h"

void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
	mpf_add (out1, in1, in2);
	mpf_div_ui (out1, out1, 2);
	mpf_mul (out2, in1, in2);
	mpf_sqrt (out2, out2);
}

int main (void) {
	mpf_set_default_prec (65568);
	mpf_t x0, y0, resA, resB;

	mpf_init_set_ui (y0, 1);
	mpf_init_set_d (x0, 0.5);
	mpf_sqrt (x0, x0);
	mpf_init (resA);
	mpf_init (resB);

	for(int i=0; i<7; i++){
		agm(x0, y0, resA, resB);
		agm(resA, resB, x0, y0);
	}
	gmp_printf ("%.20000Ff\n", x0);
	gmp_printf ("%.20000Ff\n\n", y0);

	return 0;
}





PHP: define('PRECISION', 13);

function agm($a0, $g0, $tolerance = 1e-10)                                                                                                    
{



    $limit = number_format($tolerance, PRECISION, '.', '');
    $an    = $a0;
    $gn    = $g0;
    do {
        list($an, $gn) = array(
            bcdiv(bcadd($an, $gn), 2), 
            bcsqrt(bcmul($an, $gn)),
        );  
    } while (bccomp(bcsub($an, $gn), $limit) > 0); 

    return $an;
}

bcscale(PRECISION);
echo agm(1, 1 / bcsqrt(2));
Task: Arithmetic-geometric mean






PHP: define('PRECISION', 13);

function agm($a0, $g0, $tolerance = 1e-10)                                                                                                    
{



    $limit = number_format($tolerance, PRECISION, '.', '');
    $an    = $a0;
    $gn    = $g0;
    do {
        list($an, $gn) = array(
            bcdiv(bcadd($an, $gn), 2), 
            bcsqrt(bcmul($an, $gn)),
        );  
    } while (bccomp(bcsub($an, $gn), $limit) > 0); 

    return $an;
}

bcscale(PRECISION);
echo agm(1, 1 / bcsqrt(2));


Python: from math import sqrt

def agm(a0, g0, tolerance=1e-10):
    
    an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
    while abs(an - gn) > tolerance:
        an, gn = (an + gn) / 2.0, sqrt(an * gn)
    return an

print agm(1, 1 / sqrt(2))
Task: Arithmetic-geometric mean






PHP: define('PRECISION', 13);

function agm($a0, $g0, $tolerance = 1e-10)                                                                                                    
{



    $limit = number_format($tolerance, PRECISION, '.', '');
    $an    = $a0;
    $gn    = $g0;
    do {
        list($an, $gn) = array(
            bcdiv(bcadd($an, $gn), 2), 
            bcsqrt(bcmul($an, $gn)),
        );  
    } while (bccomp(bcsub($an, $gn), $limit) > 0); 

    return $an;
}

bcscale(PRECISION);
echo agm(1, 1 / bcsqrt(2));



VB: Private Function agm(a As Double, g As Double, Optional tolerance As Double = 0.000000000000001) As Double
    Do While Abs(a - g) > tolerance
        tmp = a
        a = (a + g) / 2
        g = Sqr(tmp * g)
        Debug.Print a
    Loop
    agm = a
End Function
Public Sub main()
    Debug.Print agm(1, 1 / Sqr(2))
End Sub
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);




Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);





Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);







Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);








VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;


C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;




Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;






Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;







VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}



Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");
Task: Loops_For with a specified step



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}





Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step




Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}


Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");
Task: Loops_For with a specified step




Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}




Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step




Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}





VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step







Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"


VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;



Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}
Task: Loops_For with a specified step



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}






VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step





Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");




VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub
Task: Loops_For with a specified step



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}


Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}
Task: Loops_For with a specified step





Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");



Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step

C: int i;
for(i = 1; i < 10; i += 2)
  printf("%d\n", i);






PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>
Task: Loops_For with a specified step



C#: using System;
 
class Program {
    static void Main(string[] args) {    
        for (int i = 2; i <= 8; i+= 2) {        
            Console.Write("{0}, ", i);
        }

        Console.WriteLine("who do we appreciate?");
    }
}




PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>
Task: Loops_For with a specified step


C++: for (int i = 1; i < 10; i += 2)
  std::cout << i << std::endl;





PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>
Task: Loops_For with a specified step




Go: for i := 1; i < 10; i += 2 {
  fmt.Printf("%d\n", i)
}



PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>
Task: Loops_For with a specified step





Java: for(int i = 2; i <= 8;i += 2){
   System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");


PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>
Task: Loops_For with a specified step






PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>


Python: for i in xrange(2, 9, 2):
    print "%d," % i,
print "who do we appreciate?"
Task: Loops_For with a specified step






PHP: <?php
foreach (range(2, 8, 2) as $i)
    echo "$i, ";
echo "who do we appreciate?\n";
?>



VB: Sub MyLoop()
    For i = 2 To 8 Step 2
        Debug.Print i;
    Next i
    Debug.Print
End Sub