開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 5(Making Choices)、5.6(Exercises) 9.をSwiftで考えてみる。
5.6(Exercises) 9.
コード(Xcode)
main.swift
// // main.swift // sample9 // // Created by kamimura on 8/3/14. // Copyright (c) 2014 kamimura. All rights reserved. // import Foundation func isDanger (ph:Float) { if ph < 3.0 { println("\(ph) is VERY acidic! Be careful.") } else if ph < 7.0 { println("\(ph) is acidic.") } } for ph:Int in 0...9 { isDanger(Float(ph)) } for ph:Int in 0..<10 { isDanger(Float(ph)) }
入出力結果(Console Output, Assistant Editor)
0.0 is VERY acidic! Be careful. 1.0 is VERY acidic! Be careful. 2.0 is VERY acidic! Be careful. 3.0 is acidic. 4.0 is acidic. 5.0 is acidic. 6.0 is acidic. 0.0 is VERY acidic! Be careful. 1.0 is VERY acidic! Be careful. 2.0 is VERY acidic! Be careful. 3.0 is acidic. 4.0 is acidic. 5.0 is acidic. 6.0 is acidic. Program ended with exit code: 0
0 コメント:
コメントを投稿