エンジン

起動・依存

対話起動 インポート
C++ - #include <system.h>
C# - using System.Text;
Java - import java.text.*;
VB - Declare Function GetTickCount Lib "kernel32" () As Long
PHP $ php -a require('text.php');
JS $ node <script src="aaa.js"></script>
Ruby $ irb require 'text'
Python $ python from A import B
Perl $ perl -d -e 1 require CGI;
use CGI;
C++ C# Java VB PHP JS Ruby Python Perl
対話起動 - - - - $ php -a $ node $ irb $ python $ perl -d -e 1
インポート #include <system.h> using System.Text; import java.text.*; Declare Function GetTickCount Lib "kernel32" () As Long require('text.php'); <script src="aaa.js"></script> require 'text' from A import B require CGI;
use CGI;

コメント

行コメント ブロックコメント
C++ // comment /*
hello
world
*/
C# // comment /*
hello
world
*/
Java // comment /*
hello
world
*/
VB ' comment -
PHP // comment /*
hello
world
*/
JS // comment /*
hello
world
*/
Ruby # comment =begin
hello
world
=end
Python # comment '''
文字列リテラルを
代用
'''
Perl # comment =pod
hello
world
=cut
C++ C# Java VB PHP JS Ruby Python Perl
行コメント // comment // comment // comment ' comment // comment // comment # comment # comment # comment
ブロックコメント /*
hello
world
*/
/*
hello
world
*/
/*
hello
world
*/
- /*
hello
world
*/
/*
hello
world
*/
=begin
hello
world
=end
'''
文字列リテラルを
代用
'''
=pod
hello
world
=cut

変数・定数

変数宣言

変数宣言 グローバル変数 局所変数
C++ int v = 10; int g = 10; // 関数外で宣言 {
    int p = 10;
}
C# int v = 10; public static class G{
    public static int g = 10;
}
{
    int p = 10;
}
Java int v = 10; public static class G{
    public static int g = 10;
}
{
    int p = 10;
}
VB Dim v As Integer = 10; public g as Integer = 10; If True Then
    Dim p As Integer = 10
End
PHP $v = 10; global $g = 10; function foo(){
    $p = 10;
}
JS var v = 10; window.g = 10; function foo(){
    var p = 10;
}
Ruby v = 10 $g = 10 def foo
    p = 10
end
Python v = 10 global g def foo():
    p = 10
Perl my $v = 10; our $g = 10; {
    my $p = 10;
}
C++ C# Java VB PHP JS Ruby Python Perl
変数宣言 int v = 10; int v = 10; int v = 10; Dim v As Integer = 10; $v = 10; var v = 10; v = 10 v = 10 my $v = 10;
グローバル変数 int g = 10; // 関数外で宣言 public static class G{
    public static int g = 10;
}
public static class G{
    public static int g = 10;
}
public g as Integer = 10; global $g = 10; window.g = 10; $g = 10 global g our $g = 10;
局所変数 {
    int p = 10;
}
{
    int p = 10;
}
{
    int p = 10;
}
If True Then
    Dim p As Integer = 10
End
function foo(){
    $p = 10;
}
function foo(){
    var p = 10;
}
def foo
    p = 10
end
def foo():
    p = 10
{
    my $p = 10;
}

整数リテラル

10進 16進 8進 2進
C++ 255 0xFF 0377 -
C# 255 0xFF - -
Java 255 0xFF 0377 -
VB 255 &HFF &O377 -
PHP 255 0xFF 0377 0b11111111
JS 255 0xFF 0377 -
Ruby 255 0xFF 0377, 0o377 0b11111111
Python 255 0xFF 0377 0b11111111
Perl 255 0xFF 0377 0b11111111
C++ C# Java VB PHP JS Ruby Python Perl
10進 255 255 255 255 255 255 255 255 255
16進 0xFF 0xFF 0xFF &HFF 0xFF 0xFF 0xFF 0xFF 0xFF
8進 0377 - 0377 &O377 0377 0377 0377, 0o377 0377 0377
2進 - - - - 0b11111111 - 0b11111111 0b11111111 0b11111111

定数等

定数 列挙型
C++ const int C = 10; enum MyEnum{
    FOO = 10,
    BAR,
};
MyEnum e = FOO;
C# const int C = 10; enum MyEnum{
    FOO = 10,
    BAR,
}
MyEnum e = MyEnum.FOO;
Java static final int C = 10; enum MyEnum{
    FOO,
    BAR,
}
MyEnum e = MyEnum.FOO;
VB Const C As Integer = 10 Enum MyEnum
    FOO = 10
    BAR
End Enum
Dim e As MyEnum = MyEnum.FOO
PHP define('C', 10); (疑似)
abstract class MyEnum{
    const FOO = 10;
    const BAR = 11;
}
$e = MyEnum::FOO;
JS const C = 10; (疑似)
var MyEnum = {
    FOO : 10,
    BAR : 11,
};
var e = MyEnum.FOO;
Ruby C = 10 (疑似)
module MyEnum
    FOO = 10
    BAR = 11
end
e = MyEnum::FOO
Python - (疑似)
from enum import Enum
class MyEnum(Enum):
    FOO = 10
    BAR = 11
e = MyEnum.FOO
Perl use constant C => 10; (疑似)
use enum qw(One=1 Ten=10);
$a = One;
C++ C# Java VB PHP JS Ruby Python Perl
定数 const int C = 10; const int C = 10; static final int C = 10; Const C As Integer = 10 define('C', 10); const C = 10; C = 10 - use constant C => 10;
列挙型 enum MyEnum{
    FOO = 10,
    BAR,
};
MyEnum e = FOO;
enum MyEnum{
    FOO = 10,
    BAR,
}
MyEnum e = MyEnum.FOO;
enum MyEnum{
    FOO,
    BAR,
}
MyEnum e = MyEnum.FOO;
Enum MyEnum
    FOO = 10
    BAR
End Enum
Dim e As MyEnum = MyEnum.FOO
(疑似)
abstract class MyEnum{
    const FOO = 10;
    const BAR = 11;
}
$e = MyEnum::FOO;
(疑似)
var MyEnum = {
    FOO : 10,
    BAR : 11,
};
var e = MyEnum.FOO;
(疑似)
module MyEnum
    FOO = 10
    BAR = 11
end
e = MyEnum::FOO
(疑似)
from enum import Enum
class MyEnum(Enum):
    FOO = 10
    BAR = 11
e = MyEnum.FOO
(疑似)
use enum qw(One=1 Ten=10);
$a = One;

無効値

無効値定数 無効値判定
C++ false
NULL
if(boolValue){ … }
if(pointerValue){ … }
if(pointerValue != NULL){ … }
C# false
null
if(boolValue){ … }
if(refValue != null){ … }
Java false
null
if(boolValue){ … }
if(refValue != null){ … }
VB Nothing
vbEmpty
vbNull
vbNullString
String.Empty
Double.NaN
If Not IsNothing(v) Then …
If Not v Is Nothing Then …
If Not String.IsNullOrEmpty(v) Then …
If Not Double.IsNaN(v) Then …
PHP FALSE
NULL
if(!empty($v)){ … }
if(!is_null($v)){ … }
if(!isset($v)){ … }
if($v){ … }
JS undefined
null
NaN
if(v){ … }
if(v !== null){ … }
if(typeof v !== 'undefined'){ … ]
if(v !== NaN){ … }
Ruby false
nil
if !v.nil? …
if !v.empty? …
if !v.blank? …
Python False, None if(v): …
if(v is not None): …
Perl - if($v){ … }
if(defined($v)){ … }
C++ C# Java VB PHP JS Ruby Python Perl
無効値定数 false
NULL
false
null
false
null
Nothing
vbEmpty
vbNull
vbNullString
String.Empty
Double.NaN
FALSE
NULL
undefined
null
NaN
false
nil
False, None -
無効値判定 if(boolValue){ … }
if(pointerValue){ … }
if(pointerValue != NULL){ … }
if(boolValue){ … }
if(refValue != null){ … }
if(boolValue){ … }
if(refValue != null){ … }
If Not IsNothing(v) Then …
If Not v Is Nothing Then …
If Not String.IsNullOrEmpty(v) Then …
If Not Double.IsNaN(v) Then …
if(!empty($v)){ … }
if(!is_null($v)){ … }
if(!isset($v)){ … }
if($v){ … }
if(v){ … }
if(v !== null){ … }
if(typeof v !== 'undefined'){ … ]
if(v !== NaN){ … }
if !v.nil? …
if !v.empty? …
if !v.blank? …
if(v): …
if(v is not None): …
if($v){ … }
if(defined($v)){ … }

真偽

True定数 False定数 True判定 False判定
C++ true false False判定以外 false, 0, NULL
C# true false true false
Java true false true false
VB True False True False
PHP TRUE (※大小文字区別無) FALSE (※大小文字区別無) False判定以外 FALSE, 0, NULL, '', '0', [], 未定義
JS true false False判定以外 false, undefined, 0, ''
Ruby true false False判定以外 false, nil
Python True False False判定以外 False, 0, '', (), [], {}
Perl - - False判定以外 0, '', '0'
C++ C# Java VB PHP JS Ruby Python Perl
True定数 true true true True TRUE (※大小文字区別無) true true True -
False定数 false false false False FALSE (※大小文字区別無) false false False -
True判定 False判定以外 true true True False判定以外 False判定以外 False判定以外 False判定以外 False判定以外
False判定 false, 0, NULL false false False FALSE, 0, NULL, '', '0', [], 未定義 false, undefined, 0, '' false, nil False, 0, '', (), [], {} 0, '', '0'

演算

論理演算

論理OR 論理AND 論理NOT
C++ a = b || c; a = b && c; a = !b;
C# a = b || c; a = b && c; a = !b;
Java a = b || c; a = b && c; a = !b;
VB a = b Or c a = b And c a = Not b
PHP a = $b || $c; a = $b && $c; a = !$b;
JS a = b || c; a = b && c; a = !b;
Ruby a = b || c
a = (b or c)
a = b && c
a = (b or c)
a = !b
a = (not b)
Python a = b || c; a = b && c; a = !b;
Perl $a = $b || $c;
$a = ($b or $c);
$a = $b && $c;
$a = ($b and $c);
$a = !$b;
$a = not $b;
C++ C# Java VB PHP JS Ruby Python Perl
論理OR a = b || c; a = b || c; a = b || c; a = b Or c a = $b || $c; a = b || c; a = b || c
a = (b or c)
a = b || c; $a = $b || $c;
$a = ($b or $c);
論理AND a = b && c; a = b && c; a = b && c; a = b And c a = $b && $c; a = b && c; a = b && c
a = (b or c)
a = b && c; $a = $b && $c;
$a = ($b and $c);
論理NOT a = !b; a = !b; a = !b; a = Not b a = !$b; a = !b; a = !b
a = (not b)
a = !b; $a = !$b;
$a = not $b;

ビット演算

ビットOR ビットAND ビットNOT ビットXOR ビットシフト
C++ a = b | c; a = b & c; a = ~b; a = b ^ c; a = b << 2;
a = b >> 2;
C# a = b | c; a = b & c; a = ~b; a = b ^ c; a = b << 2;
a = b >> 2;
Java a = b | c; a = b & c; a = ~b; a = b ^ c; a = b << 2;
a = b >> 2;
VB a = b Or c a = b And c a = Not b a = b Xor c a = b << 2
a = b >> 2
PHP $a = $b | $c; $a = $b & $c; $a = ~$b; $a = $b ^ $c; $a = $b << 2;
$a = $b >> 2;
JS a = b | c; a = b & c; a = ~b; a = b ^ c; a = b << 2;
a = b >> 2;
Ruby a = b | c a = b & c a = ~b a = b ^ c a = b << 2
a = b >> 2
Python a = b | c; a = b & c; a = ~b; a = b ^ c; a = b << 2
a = b >> 2
Perl $a = $b | $c; $a = $b & $c; $a = ~$b; $a = $b ^ $c; $a = $b << 2;
$a = $b >> 2;
C++ C# Java VB PHP JS Ruby Python Perl
ビットOR a = b | c; a = b | c; a = b | c; a = b Or c $a = $b | $c; a = b | c; a = b | c a = b | c; $a = $b | $c;
ビットAND a = b & c; a = b & c; a = b & c; a = b And c $a = $b & $c; a = b & c; a = b & c a = b & c; $a = $b & $c;
ビットNOT a = ~b; a = ~b; a = ~b; a = Not b $a = ~$b; a = ~b; a = ~b a = ~b; $a = ~$b;
ビットXOR a = b ^ c; a = b ^ c; a = b ^ c; a = b Xor c $a = $b ^ $c; a = b ^ c; a = b ^ c a = b ^ c; $a = $b ^ $c;
ビットシフト a = b << 2;
a = b >> 2;
a = b << 2;
a = b >> 2;
a = b << 2;
a = b >> 2;
a = b << 2
a = b >> 2
$a = $b << 2;
$a = $b >> 2;
a = b << 2;
a = b >> 2;
a = b << 2
a = b >> 2
a = b << 2
a = b >> 2
$a = $b << 2;
$a = $b >> 2;

文字・文字列

文字と文字列

文字 文字列 ヒアドキュメント
C++ char c = 'A'; std::string s = "ABC\\DEF";
std::wstring s = L"ABC\\DEF";
std::string s = "Foo\n"
    + "Bar\n"
    + "Baz\n";
C# char c = 'A'; string s = "ABC\\DEF";
string s = @"ABC\DEF";
string s = @"Foo
Bar
Baz";
Java char c = 'A';
char c = '\u0041';
char c = 65;
String s = "ABC\\DEF";
String s = "\u0041BC\\DEF";
string s = "Foo\n"
    + "Bar\n"
    + "Baz\n";
VB - Dim s As String = "ABC\DEF" s = "Foo" & vbCrLf & _
    "Bar" & vbCrLf & _
    "Baz" & vbCrLf
PHP - $s = 'ABC\DEF';
$s = "ABC\\DEF";
$s = <<<EOS
Foo
Bar
Baz
EOS;
JS - s = "ABC\\DEF";
s = 'ABC\\DEF';
s = "Foo\n\
Bar\n\
Baz\
";
Ruby - s = "ABC\\DEF"
s = 'ABC\DEF'
s = <<EOS
Foo
Bar
Baz
EOS
Python - s = "ABC\\DEF"
s = 'ABC\\DEF'
s = '''
Foo
Bar
Baz
'''
Perl - my $s = "ABC\\DEF";
my $s = 'ABC\DEF';
$s = <<"EOS";
Foo
Bar
Baz
EOS
C++ C# Java VB PHP JS Ruby Python Perl
文字 char c = 'A'; char c = 'A'; char c = 'A';
char c = '\u0041';
char c = 65;
- - - - - -
文字列 std::string s = "ABC\\DEF";
std::wstring s = L"ABC\\DEF";
string s = "ABC\\DEF";
string s = @"ABC\DEF";
String s = "ABC\\DEF";
String s = "\u0041BC\\DEF";
Dim s As String = "ABC\DEF" $s = 'ABC\DEF';
$s = "ABC\\DEF";
s = "ABC\\DEF";
s = 'ABC\\DEF';
s = "ABC\\DEF"
s = 'ABC\DEF'
s = "ABC\\DEF"
s = 'ABC\\DEF'
my $s = "ABC\\DEF";
my $s = 'ABC\DEF';
ヒアドキュメント std::string s = "Foo\n"
    + "Bar\n"
    + "Baz\n";
string s = @"Foo
Bar
Baz";
string s = "Foo\n"
    + "Bar\n"
    + "Baz\n";
s = "Foo" & vbCrLf & _
    "Bar" & vbCrLf & _
    "Baz" & vbCrLf
$s = <<<EOS
Foo
Bar
Baz
EOS;
s = "Foo\n\
Bar\n\
Baz\
";
s = <<EOS
Foo
Bar
Baz
EOS
s = '''
Foo
Bar
Baz
'''
$s = <<"EOS";
Foo
Bar
Baz
EOS

比較と抽出

文字列比較 文字列検索 文字列抽出
C++ if(a == b){ … }
if(a != b){ … }
int pos = a.find("keyword", 0); std::string s = a.substr(10, 5);
C# if(a == b){ … }
if(a != b){ … }
int pos = a.IndexOf("keyword"); string s = a.substr(10, 5);
Java if(a.equals(b)){ … }
if(!a.equals(b)){ … }
int pos = a.IndexOf("keyword"); String s = a.substring(10, 15);
VB If a = b Then …
If a <> b Then …
Dim pos As Integer = InStr(1, a, "keyword") Dim s As String = Mid(a, 10, 5)
PHP if($a === b){ … }
if($a !== b){ … }
$pos = strpos($a, "keyword"); $s = substr($a, 10, 5);
JS if(a === b){ … }
if(a !== b){ … }
var pos = a.indexOf("keyword"); var s = a.substr(10, 5);
var s = a.substring(10, 15);
Ruby if a == b …
if a != b …
pos = a.index("keyword") s = a[10, 5]
Python if a == b: …
if a != b: …
pos = a.index("keyword") s = a[10:15]
Perl if($a eq $b){ … }
if($a ne $b){ … }
my $pos = index($a, "keyword"); my $s = substr($a, 10, 5);
C++ C# Java VB PHP JS Ruby Python Perl
文字列比較 if(a == b){ … }
if(a != b){ … }
if(a == b){ … }
if(a != b){ … }
if(a.equals(b)){ … }
if(!a.equals(b)){ … }
If a = b Then …
If a <> b Then …
if($a === b){ … }
if($a !== b){ … }
if(a === b){ … }
if(a !== b){ … }
if a == b …
if a != b …
if a == b: …
if a != b: …
if($a eq $b){ … }
if($a ne $b){ … }
文字列検索 int pos = a.find("keyword", 0); int pos = a.IndexOf("keyword"); int pos = a.IndexOf("keyword"); Dim pos As Integer = InStr(1, a, "keyword") $pos = strpos($a, "keyword"); var pos = a.indexOf("keyword"); pos = a.index("keyword") pos = a.index("keyword") my $pos = index($a, "keyword");
文字列抽出 std::string s = a.substr(10, 5); string s = a.substr(10, 5); String s = a.substring(10, 15); Dim s As String = Mid(a, 10, 5) $s = substr($a, 10, 5); var s = a.substr(10, 5);
var s = a.substring(10, 15);
s = a[10, 5] s = a[10:15] my $s = substr($a, 10, 5);

文字列加工

文字列結合 変数埋め込み 文字列整形
C++ std::string s = a + b; std::string s = "Hello " + world; char f[64];
sprintf(f, "Hello %04d %s", 10, "World");
C# string s = a + b; string s = "Hello " + world; string f = String.Format("Hello {0:D4} {1}", 10, "World");
Java String s = a + b; String s = "Hello " + world; String f = String.format("Hello %04d %s", 10, "World");
VB Dim s As String = a & b s = "Hello " & world Dim f As String = "Hello " & (10).ToString("D4") & " World"
PHP $s = $a . $b; $s = "Hello " + $world; $f = sprintf("Hello %04d %s", 10, "World");
JS my s = a + b; var s = "Hello $world"; // (ライブラリ利用)
// https://github.com/alexei/sprintf.js
var f = sprintf("Hello %04d %s", 10, "World");
Ruby c = a + b s = "Hello #{world}" f = sprintf("Hello %04d %s", 10, "World")
Python c = a + b s = "Hello %s" % world f = "Hello %04d %s" % (10, "World")
Perl my $c = $a . $b; my $s = "Hello ${world}"; $f = sprintf("Hello %04d %s", 10, "World");
C++ C# Java VB PHP JS Ruby Python Perl
文字列結合 std::string s = a + b; string s = a + b; String s = a + b; Dim s As String = a & b $s = $a . $b; my s = a + b; c = a + b c = a + b my $c = $a . $b;
変数埋め込み std::string s = "Hello " + world; string s = "Hello " + world; String s = "Hello " + world; s = "Hello " & world $s = "Hello " + $world; var s = "Hello $world"; s = "Hello #{world}" s = "Hello %s" % world my $s = "Hello ${world}";
文字列整形 char f[64];
sprintf(f, "Hello %04d %s", 10, "World");
string f = String.Format("Hello {0:D4} {1}", 10, "World"); String f = String.format("Hello %04d %s", 10, "World"); Dim f As String = "Hello " & (10).ToString("D4") & " World" $f = sprintf("Hello %04d %s", 10, "World"); // (ライブラリ利用)
// https://github.com/alexei/sprintf.js
var f = sprintf("Hello %04d %s", 10, "World");
f = sprintf("Hello %04d %s", 10, "World") f = "Hello %04d %s" % (10, "World") $f = sprintf("Hello %04d %s", 10, "World");

制御

分岐

If分岐 Switch分岐
C++ if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
C# if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
Java if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
VB If a Then
    foo()
ElseIf b Then
    bar()
Else
    baz()
End If
Select Case v
    Case 0
        foo()
    Case 1
        bar()
    Case Else
        baz()
End Select
PHP if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
JS if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
Ruby if a
    foo()
elsif b
    bar()
else
    baz()
end
case a
when 0
    foo()
when 1
    bar()
else
    baz()
end
Python if a:
    foo()
elif b:
    bar()
else:
    baz()
-
Perl if(a){
    foo();
}
elsif(b){
    bar();
}
else{
    baz();
}
use Switch;
switch($a){
    case 0 { foo(); }
    case 1 { bar(); }
    else { baz(); }
}
C++ C# Java VB PHP JS Ruby Python Perl
If分岐 if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
If a Then
    foo()
ElseIf b Then
    bar()
Else
    baz()
End If
if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
if(a){
    foo();
}
else if(b){
    bar();
}
else{
    baz();
}
if a
    foo()
elsif b
    bar()
else
    baz()
end
if a:
    foo()
elif b:
    bar()
else:
    baz()
if(a){
    foo();
}
elsif(b){
    bar();
}
else{
    baz();
}
Switch分岐 switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
Select Case v
    Case 0
        foo()
    Case 1
        bar()
    Case Else
        baz()
End Select
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
switch(a){
case 0:
    foo();
    break;
case 1:
    bar();
    break;
default:
    baz();
    break;
}
case a
when 0
    foo()
when 1
    bar()
else
    baz()
end
- use Switch;
switch($a){
    case 0 { foo(); }
    case 1 { bar(); }
    else { baz(); }
}

ループ

Forループ ForEachループ Whileループ
C++ for(int i = 0; i < 10; i++){
    std::out << i << "\n";
}
std::vector list;
BOOST_FOREACH(int e, list){
    std::cout << e;
}
while(a){
    foo();
}
C# for(int i = 0; i < 10; i++){
    System.Console.WriteLine("" + i);
}
List list;
foreach (int e in list){
    Console.WriteLine(e);
}
while(a){
    foo();
}
Java for(int i = 0; i < 10; i++){
    System.out.println("" + i);
}
ArrayList list;
for(Integer e : list){
    System.out.println("" + e);
}
while(a){
    foo();
}
VB For i = 0 To 9
    System.Console.WriteLine(i)
Next
Dim a As New ArrayList
For Each e As String In a
    Console.WriteLine(e)
Next
Do While a
    foo()
Loop
While a
    foo()
End While
PHP for($i = 0; $i < 10; $i++){
    print "$i\n";
}
foreach($list as $e){
    print "$e\n";
}
while($a){
    foo();
}
JS for($i = 0; $i < 10; $i++){
    console.log($i);
}
list.forEach(function(e, i){
    console.log(e);
}
while(a){
    foo();
}
Ruby for i in 0..9 do
    puts "#{i}"
end
list.each do |e|
    puts e
end
while a
    foo()
end
Python for i in range(0, 10):
    print i
for e in list:
    print e
while a:
    foo()
Perl for(my $i = 0; $i < 10; $i++){
    print "$i\n";
}
foreach my $e (@list){
    print "$e\n";
}
while($a){
    foo();
}
C++ C# Java VB PHP JS Ruby Python Perl
Forループ for(int i = 0; i < 10; i++){
    std::out << i << "\n";
}
for(int i = 0; i < 10; i++){
    System.Console.WriteLine("" + i);
}
for(int i = 0; i < 10; i++){
    System.out.println("" + i);
}
For i = 0 To 9
    System.Console.WriteLine(i)
Next
for($i = 0; $i < 10; $i++){
    print "$i\n";
}
for($i = 0; $i < 10; $i++){
    console.log($i);
}
for i in 0..9 do
    puts "#{i}"
end
for i in range(0, 10):
    print i
for(my $i = 0; $i < 10; $i++){
    print "$i\n";
}
ForEachループ std::vector list;
BOOST_FOREACH(int e, list){
    std::cout << e;
}
List list;
foreach (int e in list){
    Console.WriteLine(e);
}
ArrayList list;
for(Integer e : list){
    System.out.println("" + e);
}
Dim a As New ArrayList
For Each e As String In a
    Console.WriteLine(e)
Next
foreach($list as $e){
    print "$e\n";
}
list.forEach(function(e, i){
    console.log(e);
}
list.each do |e|
    puts e
end
for e in list:
    print e
foreach my $e (@list){
    print "$e\n";
}
Whileループ while(a){
    foo();
}
while(a){
    foo();
}
while(a){
    foo();
}
Do While a
    foo()
Loop
While a
    foo()
End While
while($a){
    foo();
}
while(a){
    foo();
}
while a
    foo()
end
while a:
    foo()
while($a){
    foo();
}

ジャンプ

ループ抜け ループ継続
C++ break; continue;
C# break; continue;
Java break; continue;
VB Exit For
Exit While
Exit Do
Continue For
Continue While
Continue Do
PHP break; continue;
JS break; continue;
Ruby break next
Python break continue
Perl last; next;
C++ C# Java VB PHP JS Ruby Python Perl
ループ抜け break; break; break; Exit For
Exit While
Exit Do
break; break; break break last;
ループ継続 continue; continue; continue; Continue For
Continue While
Continue Do
continue; continue; next continue next;

例外

例外送出 例外Catch
C++ throw std::exception("msg");
throw "msg";
throw 10;
try{
}
catch(const std::exception& ex){
}
catch(const char* ex){
}
catch(int ex){
}
catch(...){
}
C# throw new Exception("msg"); try{
}
catch(Exception ex){
}
catch{
}
finally{
}
Java throw new Exception("msg"); try{
}
catch(Exception ex){
}
finally{
}
VB Throw New Exception("msg") ' (Try~Catchを使う方法)
Try
    …
Catch ex As Exception
    …
End Try

' (On Errorを使う方法)
On Error Goto ErrorLabel

Exit Sub
ErrorLabel:
PHP throw new Exception("msg"); try{
}
catch(Exception $ex){
}
finally{ // ※PHP5.5~
}
JS throw new Error("msg");
throw "msg";
throw 10;
try{
}
catch(ex){
}
finally{
}
Ruby raise "msg"
raise Exception.new("msg")
begin
    …
rescue Exception => ex
    …
rescue => ex
    …
ensure
    …
end
Python raise Exception("msg") try:
    pass
except Exception as ex:
    pass
except:
    pass
else:
    pass
finally:
    pass
Perl - eval{
    …
};
if($@){
    print "Error: $@\n";
}
C++ C# Java VB PHP JS Ruby Python Perl
例外送出 throw std::exception("msg");
throw "msg";
throw 10;
throw new Exception("msg"); throw new Exception("msg"); Throw New Exception("msg") throw new Exception("msg"); throw new Error("msg");
throw "msg";
throw 10;
raise "msg"
raise Exception.new("msg")
raise Exception("msg") -
例外Catch try{
}
catch(const std::exception& ex){
}
catch(const char* ex){
}
catch(int ex){
}
catch(...){
}
try{
}
catch(Exception ex){
}
catch{
}
finally{
}
try{
}
catch(Exception ex){
}
finally{
}
' (Try~Catchを使う方法)
Try
    …
Catch ex As Exception
    …
End Try

' (On Errorを使う方法)
On Error Goto ErrorLabel

Exit Sub
ErrorLabel:
try{
}
catch(Exception $ex){
}
finally{ // ※PHP5.5~
}
try{
}
catch(ex){
}
finally{
}
begin
    …
rescue Exception => ex
    …
rescue => ex
    …
ensure
    …
end
try:
    pass
except Exception as ex:
    pass
except:
    pass
else:
    pass
finally:
    pass
eval{
    …
};
if($@){
    print "Error: $@\n";
}

構造

関数

関数定義 関数利用 参照渡し 参照渡し利用
C++ int foo(int a, int b){
    return a + b;
}
int n = foo(10, 20); void bar(int& r){
    r = 10;
}
int n = 0;
bar(n);
C# int foo(int a, int b){
    return a + b;
}
int n = foo(10, 20); void bar(out int r){
    r = 10;
}
int n = 0;
bar(out n);
Java int foo(int a, int b){
    return a + b;
}
int n = foo(10, 20); void bar(Hoge r){
    r.fuga = 10;
}
Hoge h = new Hoge();
bar(h);
VB Function foo(ByVal a As Integer, _
             ByVal b As Integer) As Integer
    foo = a + b
End Function
Dim n As Integer = foo(10, 20) Sub bar(ByRef a As Integer)
    a = 10
End Sub
Dim n As Integer = 0
bar(n)
PHP function foo($a, $b){
    return $a + $b;
}
$n = foo(10, 20); function bar(&$r){
    $r = 10;
}
$n = 0;
bar($n);
JS function foo(a, b){
    return a + b;
}
var n = foo(10, 20); function bar(r){
    r.fuga = 10;
}
var hoge = {fuga: 0};
bar(hoge);
Ruby def foo(a, b)
    return a + b
end
n = foo(10, 20) def bar(r)
    r[0] = 10
end
hoge = [0]
bar(hoge)
Python def foo(a, b):
    return a + b
n = foo(10, 20) def bar(r):
    r["fuga"] = 10
hoge = {"fuga": 0}
bar(hoge)
Perl sub foo{
    my ($a, $b) = @_;
    return $a + $b;
}
my $n = foo(10, 20); sub bar{
    $_[0] = 10;
}
$a = 1;
bar($a);
print "$a\n";
C++ C# Java VB PHP JS Ruby Python Perl
関数定義 int foo(int a, int b){
    return a + b;
}
int foo(int a, int b){
    return a + b;
}
int foo(int a, int b){
    return a + b;
}
Function foo(ByVal a As Integer, _
             ByVal b As Integer) As Integer
    foo = a + b
End Function
function foo($a, $b){
    return $a + $b;
}
function foo(a, b){
    return a + b;
}
def foo(a, b)
    return a + b
end
def foo(a, b):
    return a + b
sub foo{
    my ($a, $b) = @_;
    return $a + $b;
}
関数利用 int n = foo(10, 20); int n = foo(10, 20); int n = foo(10, 20); Dim n As Integer = foo(10, 20) $n = foo(10, 20); var n = foo(10, 20); n = foo(10, 20) n = foo(10, 20) my $n = foo(10, 20);
参照渡し void bar(int& r){
    r = 10;
}
void bar(out int r){
    r = 10;
}
void bar(Hoge r){
    r.fuga = 10;
}
Sub bar(ByRef a As Integer)
    a = 10
End Sub
function bar(&$r){
    $r = 10;
}
function bar(r){
    r.fuga = 10;
}
def bar(r)
    r[0] = 10
end
def bar(r):
    r["fuga"] = 10
sub bar{
    $_[0] = 10;
}
参照渡し利用 int n = 0;
bar(n);
int n = 0;
bar(out n);
Hoge h = new Hoge();
bar(h);
Dim n As Integer = 0
bar(n)
$n = 0;
bar($n);
var hoge = {fuga: 0};
bar(hoge);
hoge = [0]
bar(hoge)
hoge = {"fuga": 0}
bar(hoge)
$a = 1;
bar($a);
print "$a\n";

クラス

クラス定義 クラス継承 クラス利用
C++ class A{
protected:
    int m_n;
public:
    A(int n) : m_n(n){
        std::cout << "A init\n";
    }
    virtual ~A(){
        std::cout << "A final\n";
    }
    virtual void foo(int n){
        printf("A foo %d %d\n", this->m_n, n);
    }
};
class B : public A{
public:
    B(int n) : A(n){
        std::cout << "B init\n";
    }
    ~B(){
        std::cout << "B final\n";
    }
    void foo(int n){
        __super::foo(n);
        printf("B foo %d %d\n", this->m_n, n);
    }
};
B b(10);
b.foo(20);
C# class A{
    protected int m_n = 0;
    public A(int n){
        Console.WriteLine("A init");
        m_n = n;
    }
    ~A(){
        Console.WriteLine("A final");
    }
    public virtual void foo(int n){
        Console.WriteLine("A foo {0} {1}", this.m_n, n);
    }
};
class B : A{
    public B(int n) : base(n){
        Console.WriteLine("B init");
    }
    ~B(){
        Console.WriteLine("B final");
    }
    public override void foo(int n){
        base.foo(n);
        Console.WriteLine("B foo {0} {1}", this.m_n, n);
    }
}
B b = new B(10);
b.foo(20);
Java public class A{
    protected int m_n = 0;
    public A(int n){
        this.m_n = 0;
        System.out.println("A init");
    }
    public void foo(int n){
        System.out.printf("A foo %d %d\n", this.m_n, n);
    }
}
public class B extends A{
    public B(int n){
        super(n);
        System.out.println("B init");
    }
    @Override
    public void foo(int n){
        super.foo(n);
        System.out.printf("B foo %d %d\n", this.m_n, n);
    }
}
B b = new B(10);
b.foo(20);
VB Public Class A
    Protected m_n As Integer = 0
    Public Sub New(ByVal n As Integer)
        Me.m_n = n
        Console.WriteLine("A init")
    End Sub
    Protected Overrides Sub Finalize()
        Console.WriteLine("A final")
    End Sub
    Public Overridable Sub foo(ByVal n As Integer)
        Console.WriteLine("A foo {0} {1}", Me.m_n, n)
    End Sub
End Class
Public Class B
    Inherits A
    
    Public Sub New(ByVal n As Integer)
        MyBase.New(n)
        Console.WriteLine("B init")
    End Sub
    Protected Overrides Sub Finalize()
        Console.WriteLine("B final")
        MyBase.Finalize()
    End Sub
    Public Overrides Sub foo(ByVal n As Integer)
        MyBase.foo(n)
        Console.WriteLine("B foo {0} {1}", Me.m_n, n)
    End Sub
End Class
Dim ins As B
ins = new B(10)
ins.foo(20)
PHP class A{
    protected $m_n = 0;
    public function __construct($n){
        $this->m_n = $n;
        print "A init\n";
    }
    public function __destruct(){
        print "A final\n";
    }
    public function foo($n){
        print "A foo {$this->m_n} {$n}\n";
    }
}
class B extends A{
    public function __construct($n){
        parent::__construct($n);
        print "B init\n";
    }
    public function __destruct(){
        print "B final\n";
        parent::__destruct();
    }
    public function foo($n){
        print "B foo {$this->m_n} {$n}\n";
    }
}
$b = new B(10);
$b.foo(20);
JS var A = function(n){
    console.log("A init");
    this.m_n = n;
};
A.prototype.foo = function(n){
    console.log("A foo " + this.m_n + " " + n);
};
var B = function(n){
    A.call(this, n);
    console.log("B init");
};
B.prototype.foo = function(n){
    A.prototype.foo.call(this, n);
    console.log("B foo " + this.m_n + " " + n);
};
var b = new B(10);
b.foo(20);
Ruby class A
    def initialize(n)
        @m_n = n
        puts "A init"
    end
    def foo(n)
        puts "A foo #{@m_n} #{n}"
    end
end
class B < A
    def initialize(n)
        super(n)
        puts "B init"
    end
    def foo(n)
        super(n)
        puts "B foo #{@m_n} #{n}"
    end
end
b = B.new(10)
b.foo(20)
Python class A:
    def __init__(self, n):
        print "A init"
        self.m_n = n
    def __del__(self):
        print "A final"
    def foo(self, n):
        print "A foo %d %d" % (self.m_n, n)
class B(A):
    base = A
    def __init__(self, n):
        A.__init__(self, n)
        print "B init"
    def __del__(self):
        print "B final"
        self.base.__del__(self)
    def foo(self, n):
        A.foo(self, n)
        print "B foo %d %d" % (self.m_n, n)
b = B(10)
b.foo(20)
Perl package A;
sub new{
    my $class = shift;
    my $n = shift;
    print "A init\n";
    my $self = {
        m_n => $n,
    };
    return bless $self, $class;
}
sub DESTROY{
    my $self = shift;
    print "A final\n";
}
sub foo{
    my $self = shift;
    my $n = shift;
    print "A foo $self->{m_n} $n\n";
}
package B;
use base qw(A);
sub new{
    my $class = shift;
    my $n = shift;
    my $self = A->new($n);
    print "B init\n";
    return bless $self, $class;
}
sub DESTROY{
    my $self = shift;
    print "B final\n";
    $self->A::DESTROY();
}
sub foo{
    my $self = shift;
    my $n = shift;
    $self->A::foo($n);
    print "B foo $self->{m_n} $n\n";
}
package main;
use B;
my $b = B->new(10);
$b->foo(20);
C++ C# Java VB PHP JS Ruby Python Perl
クラス定義 class A{
protected:
    int m_n;
public:
    A(int n) : m_n(n){
        std::cout << "A init\n";
    }
    virtual ~A(){
        std::cout << "A final\n";
    }
    virtual void foo(int n){
        printf("A foo %d %d\n", this->m_n, n);
    }
};
class A{
    protected int m_n = 0;
    public A(int n){
        Console.WriteLine("A init");
        m_n = n;
    }
    ~A(){
        Console.WriteLine("A final");
    }
    public virtual void foo(int n){
        Console.WriteLine("A foo {0} {1}", this.m_n, n);
    }
};
public class A{
    protected int m_n = 0;
    public A(int n){
        this.m_n = 0;
        System.out.println("A init");
    }
    public void foo(int n){
        System.out.printf("A foo %d %d\n", this.m_n, n);
    }
}
Public Class A
    Protected m_n As Integer = 0
    Public Sub New(ByVal n As Integer)
        Me.m_n = n
        Console.WriteLine("A init")
    End Sub
    Protected Overrides Sub Finalize()
        Console.WriteLine("A final")
    End Sub
    Public Overridable Sub foo(ByVal n As Integer)
        Console.WriteLine("A foo {0} {1}", Me.m_n, n)
    End Sub
End Class
class A{
    protected $m_n = 0;
    public function __construct($n){
        $this->m_n = $n;
        print "A init\n";
    }
    public function __destruct(){
        print "A final\n";
    }
    public function foo($n){
        print "A foo {$this->m_n} {$n}\n";
    }
}
var A = function(n){
    console.log("A init");
    this.m_n = n;
};
A.prototype.foo = function(n){
    console.log("A foo " + this.m_n + " " + n);
};
class A
    def initialize(n)
        @m_n = n
        puts "A init"
    end
    def foo(n)
        puts "A foo #{@m_n} #{n}"
    end
end
class A:
    def __init__(self, n):
        print "A init"
        self.m_n = n
    def __del__(self):
        print "A final"
    def foo(self, n):
        print "A foo %d %d" % (self.m_n, n)
package A;
sub new{
    my $class = shift;
    my $n = shift;
    print "A init\n";
    my $self = {
        m_n => $n,
    };
    return bless $self, $class;
}
sub DESTROY{
    my $self = shift;
    print "A final\n";
}
sub foo{
    my $self = shift;
    my $n = shift;
    print "A foo $self->{m_n} $n\n";
}
クラス継承 class B : public A{
public:
    B(int n) : A(n){
        std::cout << "B init\n";
    }
    ~B(){
        std::cout << "B final\n";
    }
    void foo(int n){
        __super::foo(n);
        printf("B foo %d %d\n", this->m_n, n);
    }
};
class B : A{
    public B(int n) : base(n){
        Console.WriteLine("B init");
    }
    ~B(){
        Console.WriteLine("B final");
    }
    public override void foo(int n){
        base.foo(n);
        Console.WriteLine("B foo {0} {1}", this.m_n, n);
    }
}
public class B extends A{
    public B(int n){
        super(n);
        System.out.println("B init");
    }
    @Override
    public void foo(int n){
        super.foo(n);
        System.out.printf("B foo %d %d\n", this.m_n, n);
    }
}
Public Class B
    Inherits A
    
    Public Sub New(ByVal n As Integer)
        MyBase.New(n)
        Console.WriteLine("B init")
    End Sub
    Protected Overrides Sub Finalize()
        Console.WriteLine("B final")
        MyBase.Finalize()
    End Sub
    Public Overrides Sub foo(ByVal n As Integer)
        MyBase.foo(n)
        Console.WriteLine("B foo {0} {1}", Me.m_n, n)
    End Sub
End Class
class B extends A{
    public function __construct($n){
        parent::__construct($n);
        print "B init\n";
    }
    public function __destruct(){
        print "B final\n";
        parent::__destruct();
    }
    public function foo($n){
        print "B foo {$this->m_n} {$n}\n";
    }
}
var B = function(n){
    A.call(this, n);
    console.log("B init");
};
B.prototype.foo = function(n){
    A.prototype.foo.call(this, n);
    console.log("B foo " + this.m_n + " " + n);
};
class B < A
    def initialize(n)
        super(n)
        puts "B init"
    end
    def foo(n)
        super(n)
        puts "B foo #{@m_n} #{n}"
    end
end
class B(A):
    base = A
    def __init__(self, n):
        A.__init__(self, n)
        print "B init"
    def __del__(self):
        print "B final"
        self.base.__del__(self)
    def foo(self, n):
        A.foo(self, n)
        print "B foo %d %d" % (self.m_n, n)
package B;
use base qw(A);
sub new{
    my $class = shift;
    my $n = shift;
    my $self = A->new($n);
    print "B init\n";
    return bless $self, $class;
}
sub DESTROY{
    my $self = shift;
    print "B final\n";
    $self->A::DESTROY();
}
sub foo{
    my $self = shift;
    my $n = shift;
    $self->A::foo($n);
    print "B foo $self->{m_n} $n\n";
}
クラス利用 B b(10);
b.foo(20);
B b = new B(10);
b.foo(20);
B b = new B(10);
b.foo(20);
Dim ins As B
ins = new B(10)
ins.foo(20)
$b = new B(10);
$b.foo(20);
var b = new B(10);
b.foo(20);
b = B.new(10)
b.foo(20)
b = B(10)
b.foo(20)
package main;
use B;
my $b = B->new(10);
$b->foo(20);