LoginSignup
2
2

More than 5 years have passed since last update.

swiftでFizzBuzz

Posted at

さっきはオブジェクト指向+C#でFizzBuzzでしたが、
今回は、swift。

どんなもんかなってことで、「hello world」的な感じ書いてみました。

// Playground - noun: a place where people can play

import Cocoa

let MAX = 20
var output = ""

for i in 1...MAX {

    output = ""

    if ( i % 3 == 0 ) {
        output += "Fizz"
    }

    if ( i % 5 == 0 ) {
        output += "Buzz"
    }

    if ( output == "") {
        output = String(i)
    }

    println(output)

}

ちなみに第1印象はcoffeescriptでした。
今回は使ってませんが、クロージャー等のstabby lambdaの使い方とか。
(まぁRubyっぽくもあるけど)

それと、全然関係ないですが、Playgroundすぐ落ちる。
マシンが弱い?or betaだから?

次はオブジェクト指向的に書いてみたいと思います。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2