開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta
- Swift (プログラミング言語)
Head First JavaScript Programming (Eric T. Freeman (著)、 Elisabeth Robson (著)、 O'Reilly Media )のChapter 4(Putting Some Order in Your Data: Arrays)、SHARPEN YOUR PENCIL(p.141)をSwiftで考えてみる。
SHARPEN YOUR PENCIL(p.141)
コード(Xcode)
main.swift
// // main.swift // sample141 // // Created by kamimura on 8/6/14. // Copyright (c) 2014 kamimura. All rights reserved. // import Foundation var products = ["Choo Choo Chocolate", "Icy Mint", "Cake Batter", "Bubblegum"] var hasBubbleGum = [false, false, false, true]; var i = 0; let start = hasBubbleGum.startIndex let end = hasBubbleGum.endIndex for i in start..<end { if hasBubbleGum[i] { println("\(products[i]) contains bubble gum") } } for i in start...(end - 1) { if hasBubbleGum[i] { println("\(products[i]) contains bubble gum") } }
入出力結果(Console Output)
Bubblegum contains bubble gum Bubblegum contains bubble gum Program ended with exit code: 0
0 コメント:
コメントを投稿