Type Inference |
Dim x = 10 |
var x = 10 |
val x = 10 |
$x = 10; |
x = 10 |
x := 10 |
Generics |
New List(Of Integer) |
new List<int>() |
ListInt |
array() |
[] |
[]int{} |
Lambdas |
list.ForEach(Function(x) Console.WriteLine(x)) |
list.ForEach(x => Console.WriteLine(x)) |
list.foreach(x => println(x)) |
array_walk($list, function($x) { echo $x; }) |
[print(x) for x in list] |
for _, x := range list { fmt.Println(x) } |
Pattern Matching |
Select Case x Case 1 : Console.WriteLine("one") Case 2 : Console.WriteLine("two") Case Else : Console.WriteLine("other") End Select |
x switch { 1 => "one", 2 => "two", _ => "other"} |
x match { case 1 => "one"; case 2 => "two"; case _ => "other" } |
switch ($x) { case 1: echo "one"; break; case 2: echo "two"; break; default: echo "other"; break; } |
if x == 1: print("one") elif x == 2: print("two") else: print("other") |
if x == 1 { fmt.Println("one") } else if x == 2 { fmt.Println("two") } else { fmt.Println("other") } |
For Loop |
For i As Integer = 1 To 5 Console.WriteLine(i) Next |
for (int i = 1; i <= 5; i++) Console.WriteLine(i); |
for (i <- 1 to 5) println(i) |
for ($i = 1; $i <= 5; $i++): echo $i; endfor; |
for i in range(1, 6): print(i) |
for i := 1; i <= 5; i++ { fmt.Println(i) } |
While Loop |
While x < 5 Console.WriteLine(x) x = x + 1 End While |
while (x < 5) { Console.WriteLine(x); x++; } |
while (x < 5) { println(x); x += 1 } |
while (x < 5) { echo x; x++; } |
while x < 5: print(x); x += 1 |
for x < 5 { fmt.Println(x); x++ } |
Do-While Loop |
Do Console.WriteLine("loop") Loop While x > 0 |
do { Console.WriteLine("loop"); } while (x > 0); |
do { println("loop") } while (x > 0) |
do { echo "loop"; } while (x > 0); |
while True: print("loop"); if x <= 0: break |
for x > 0 { fmt.Println("loop") } |
Lambdas |
Function(x As Integer) x + 1 |
x => x + 1 |
(x: Int) => x + 1 |
function($x) { return $x + 1; }; |
lambda x: x + 1 |
func(x int) int { return x + 1 } |
Return |
Return 1 |
return 1; |
return 1 |
return 1; |
return 1 |
return 1 |
Traits |
N/A |
N/A |
trait Hello { def sayHello = println("Hello World!") } |
trait Hello { public function sayHello() { echo "Hello!"; } } |
N/A |
type Hello interface { SayHello() } |
Inheritance |
Class Cat Inherits Animal |
class Cat : Animal { } |
class Cat extends Animal |
class Cat extends Animal { } |
class Cat(Animal): pass |
type Cat struct { Animal } |
Interfaces |
Interface IShape Sub Draw() End Interface |
interface IShape { void Draw(); } |
trait IShape { def draw() } |
interface IShape { public function Draw(); } |
from abc import ABC, abstractmethod class IShape(ABC): @abstractmethod def Draw(): pass |
type IShape interface { Draw() } |