end for x in range(3): print(x) for (n <- 0 to 2) { println(n) } b = true if b then puts("true!") else puts("false!") end b = True if b: print("true!") else: print("false!") val b = true if (b) { println("true!") } else { println("false!") }
"Ruby" then puts("this is ruby") when "Python" then puts("this is python") when "Scala" then puts("this is scala") end o = "Python" if o is "Ruby": print("this is ruby!") elif o is "Python": print("this is python!") elif o is "Scala": print("this is scala!") val o = "Scala" o match { case "Ruby" => println("this is ruby!") case "Python" => println("this is python!") case "Scala" => println("this is scala!") case _ => // No Action }
} map(lambda x: x + 1, [1,2,3]) [x + 1 for x in [1, 2, 3]] List(1,2,3).map { x => x + 1 } List(1,2,3).map(_ + 1) [1,2,3].select { |x| x % 2 == 0 } filter(lambda x: x % 2 == 0, [1,2,3]) [x for x in [1,2,3] if x % 2 == 0] List(1,2,3).filter(_ % 2 == 0)
Bar include Foo def say() puts("Bar!") end end module Baz include Foo def say() puts("Baz!") end end class Qux include Bar include Baz def say() puts("Qux!") end end Qux.new.say()