This is also a comment. # This is comment, too. // /* // * /* Nested comment not work. */ // */ /* * This is a comment. */ // This is also a comment. // "#" is not a comment syntax. /* * /* Nested comment works. */ */
ExampleClass { private $privateVar = 'private var'; protected $protectedVar = 'protected var'; public $publicVar = 'public var'; const CLASS_CONST = 'class const'; } // Behavior is different from PHP // These comparison is not correct. let GLOBAL_CONST = "global const" var global = "global var" public class ExampleClass { private var privateVar = "private var" internal var internalVar = "internal var" public var publicVar = "public var" private let privateConst = "private const" internal let internalConst = "inetrnal const" public let publicConst = "public const" } private class PrivateClass {} internal class InternalClass {} public class PublicClass {}
{ case 1: $bar = 'a'; break; case 2: $bar = 'b'; break; default: $bar = 'c'; } var foo = 1 var bar = "" switch foo { case 1: bar = "a" // no need "break" case 2: bar = "b" default: bar = "c" }
< 10; $i++) { $array[] = $i; } foreach ($array as $tmp) { echo $tmp; } var array:[Int] = []; for i in 0..<10 { array.append(i) } for tmp in array { print(tmp); }
0; while ($counter1 < $max) { echo 'Hi!'; $counter1++; } do { echo 'Ho!'; $counter2++; } while ($counter2 < $max); let max = 3; var counter1 = 0; var counter2 = 0; while counter1 < max { print("Hi!") counter1++ } repeat { print("ho!") counter2++ } while counter2 < max
function foo(string $str): array { $result = []; for ($i = 0; $i < 10; $i++) { $result[] = $str . $i; } return $result; } $list = foo('x'); foreach ($list as $l) { echo $l; } func foo(str: String) -> Array<String> { var result:[String] = [] for i in 0..<10 { result.append(str + String(i)) } return result } let list = foo("x") for l in list { print(l) }
class Base { protected $bar = 'bar'; } class Example extends Base implements ExampleInterface { public function __construct() { echo 'initialize'; } public function foo(): string { return $this->bar; } } $example = new Example(); echo $example->foo(); protocol ExampleProtocol { func foo() -> String } class Base { internal let bar = "bar" } class Example: Base, ExampleProtocol { override init() { print("initialize") } func foo() -> String { return self.bar } } let example = Example() // no need 'new' print(example.foo())
''; $next = $params['next'] ?? ''; switch ($next) { case 'confirm': $html = $this->view->getConfirmHtml($params); break; case 'complete': $html = $this->view->getCompleteHtml($params); break; default: $html = $this->view->getFormHtml($params); } $this->response($html); } func run() { let params = self.parseGetVars() var html = "" let next = params["next"] ?? "" switch next { case "confirm": html = self.view.getConfirmHtml(params) case "complete": html = self.view.getCompleteHtml(params) default: html = self.view.getFormHtml(params) } self.response(html); }