「Swift入門」関数にローカル変数を使うサンプル

書式
func 関数名(ローカル引数名:データの型)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
func testFunc(cnt: Int) {
print("value: " + cnt.description)
}
testFunc(cnt: 11)
testFunc(cnt: 22)
testFunc(cnt: 33)
func testFunc(cnt: Int) { print("value: " + cnt.description) } testFunc(cnt: 11) testFunc(cnt: 22) testFunc(cnt: 33)
func testFunc(cnt: Int) {
    print("value: " + cnt.description)
}
testFunc(cnt: 11)
testFunc(cnt: 22)
testFunc(cnt: 33)

実行結果
$ swift test12.swift
value: 11
value: 22
value: 33

Swift

Posted by arkgame