Submit Search
Upload
Mobile programming control_flow2
•
0 likes
•
151 views
Yuichiro Takahashi
Follow
10/15日にのMobileProgrammingの授業のスライドです
Read less
Read more
Technology
Report
Share
Report
Share
1 of 37
Recommended
Tmux
Tmux
harutsugu shimoji
Tmux
Tmux
harutsugu shimoji
Symfony開発者がLaravelしようとして云々
Symfony開発者がLaravelしようとして云々
mimizuk
Live in commandline
Live in commandline
KotaIsozaki
Python02
Python02
XMLProJ2014
Mobile programming seigyokoubun
Mobile programming seigyokoubun
Yuichiro Takahashi
MobileProgramming Variable/Constant/Type
MobileProgramming Variable/Constant/Type
Yuichiro Takahashi
アプリだけじゃない!チームも一緒に成長させる開発
アプリだけじゃない!チームも一緒に成長させる開発
Yuichiro Takahashi
Recommended
Tmux
Tmux
harutsugu shimoji
Tmux
Tmux
harutsugu shimoji
Symfony開発者がLaravelしようとして云々
Symfony開発者がLaravelしようとして云々
mimizuk
Live in commandline
Live in commandline
KotaIsozaki
Python02
Python02
XMLProJ2014
Mobile programming seigyokoubun
Mobile programming seigyokoubun
Yuichiro Takahashi
MobileProgramming Variable/Constant/Type
MobileProgramming Variable/Constant/Type
Yuichiro Takahashi
アプリだけじゃない!チームも一緒に成長させる開発
アプリだけじゃない!チームも一緒に成長させる開発
Yuichiro Takahashi
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
CRI Japan, Inc.
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
Toru Tamaki
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
sn679259
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
atsushi061452
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
CRI Japan, Inc.
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
Toru Tamaki
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
WSO2
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
More Related Content
Recently uploaded
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
CRI Japan, Inc.
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
Toru Tamaki
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
sn679259
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
atsushi061452
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
CRI Japan, Inc.
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
Toru Tamaki
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
iPride Co., Ltd.
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
WSO2
Recently uploaded
(10)
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Mobile programming control_flow2
1.
制御構文2 MOBILEPROGRAMMING OCT, 15TH
2.
テキスト 制御構文! ▸ ifやfor-inなど分岐や繰り返し処理を特定の文に構造化したもの ▸ プログラムの構造は
順次、選択、反復の三つに分類される ▸ これらを組み合わせてプログラミングする方法を構造化プログラ ミングと呼ぶ ▸ 今回は繰り返しの構文に絞ってやって行きます ▸ 言語によってはforやwhileという構文が存在しない(or ただのシ ンタックスシュガー)
3.
1. FOR-IN
4.
テキスト FOR-IN文 ▸ 繰り返し処理をするときの基本的な構文 ▸ 構文は
for <変数> in <Array or Range> { /* loop */ } ▸ 下記のforと区別するために for-inと呼ばれます ▸ for (int i = 0; i <= 10, i++) { /* loop */ } ▸ のような構文はSwift 3.0 以降廃止されました ▸ このようなfor文をC-style forと呼びます ▸ for文は特定の回数繰り返し処理をしたいというような場合によく使います
5.
テキスト なんでC-STYLE FOR は消えた? ▸
簡潔にいうとSwiftらしくないから ▸ C言語経験者以外にはわかりにくいし ▸ 初めてSwiftを学ぶ人にとっては覚えにくい ▸ インクリメント、デクリメントによる問題もあるし for (let i = 0; i <= 10; i++) { // loop... for (let j = 0; j <= 10;, i++) { print("it's a infinity loop!") } }
6.
ではどうやって ループさせる?🤔
7.
1-1.RANGE
8.
テキスト RANGE(範囲演算子)を使う ▸ 一番簡単なやり方 ▸ switchの時に出てきたように
0…10 として 0 ~ 10までの Sequence(Array)を作成 ▸ それをfor-inと組み合わせる // Range let range = 0...10 for number in range { print("number: (number)") }
9.
テキスト FOR-IN STLIDE ▸ for-inと
stlide を使用することで間隔を開けてループさせる ことができます // 0から10まで二つとびでループ for number in stride(from: 0, to: 10, by: 2) { print("number: (number)") }
10.
1-2. ARRAY
11.
テキスト ARRAYを使う ▸ これも非常にオーソドックスなやり方 ▸ 定義済みのarrayに対してfor-inを使う ▸
indexでアクセスする方法に比べ Array の範囲外にアクセス してしまうことがないため安全 // Array let array = ["sunday", "monday", "tuesday", "wednsday", "thursday", "friday", "Saturday"] for number in array { print("number: (number)") }
12.
1-3.DICTIONARY
13.
テキスト DICTIONARYを使う ▸ これも割とオーソドックスなやり方 ▸ 定義済みのdictionaryに対してfor-inを使う ▸
key, value の形になっているため for の引数は二つになる // Dictionary let dic = ["Animal": "Cat", "Fruit": "Banana"] for (key, value) in dic { print("key: (key)") print("value: (value)") }
14.
2. WHILE
15.
テキスト WHILE文 ▸ 繰り返し処理をするときの基本的な構文 ▸ 構文は
while <ループ条件> { /* loop */ } ▸ while文は特定の条件にマッチするまで繰り返し処理をした い時に使う var count = 0 var total = 0 while count < 5 { count += 1 total += count } print("count: (count) total: (total)")
16.
3. 制御転送
17.
テキスト 制御転送(CONTROL TRANSFER STATEMENTS)?🤔 ▸
制御転送(Control Transfer Statements)はプログラムの処理 ををある場所から別の場所に移す機能のこと ▸ 例えばcontinue や break, switchのfallthroughなどがある ▸ 関数のreturnや エラー処理に出てくる throw も同じ ▸ 今回はbreakとcontinueに絞ってお話をします
18.
3-1.BREAK
19.
テキスト BREAK ▸ 他の言語同様Swiftにも break
があります ▸ 特定の条件の時にループから抜けたい場合にbreakを使用し ます for i in 0...10 { // 11回ループさせます。 if i >= 3 { // i が 3 以上になったときに抜ける break } print(i) }
20.
3-2. CONTINUE
21.
テキスト CONTINUE ▸ 他の言語同様Swiftにも continue
があります ▸ 特定の条件の時に処理をスキップしたい場合はcontinueを使 用します ▸ breakとは違いloopを抜けることはありません for i in 0...10 { if i % 3 == 0 { // 3の倍数の時はスキップ continue } print(i) }
22.
おまけ
23.
テキスト FORやWHILEを使わない?🤔 ▸ 冒頭で少しお話した通り言語によってはforやwhileが存在し ないです ▸ ではどうやって繰り返しを表現するのでしょうか? ▸
方法はいくつかあり一つは高階関数を使う方法 ▸ もう一つは再帰関数を使う方法です
24.
おまけ: 高階関 数
25.
テキスト 高階関数?🤔 ▸ 関数を引数にとったり、関数を返す関数 ▸ ややこしいので今は詳しくは説明しません ▸
繰り返しのための有名どころでは map, や forEach などがあ ります ▸ for-inを使う方法より簡潔に書くことができます
26.
テキスト たとえば?🤔 ▸ 値段のリストに対して消費税をかけた後の値段のリストを生 成する例を考えます ▸ これをfor-inで書くと次のようになります
27.
テキスト ランダムに生成した数値の倍数を求める // 消費税率 let taxRate
= 0.08 // 値段のリスト let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // まずは空の配列を生成 var newPrices = [Double]()
28.
テキスト ランダムに生成した数値の倍数を求める // 消費税率 let taxRate
= 0.08 // 値段のリスト let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // まずは空の配列を生成 var newPrices = [Double]() // for-inで一度配列から取り出して・・・ for price in prices { }
29.
テキスト ランダムに生成した数値の倍数を求める // 消費税率 let taxRate
= 0.08 // 値段のリスト let prices: [Double] = [10000, 9800, 34570, 29800, 114514] // まずは空の配列を生成 var newPrices = [Double]() // for-inで一度配列から取り出して・・・ for price in prices { let newPrice = price * taxRate newPrices.append(newPrice) // また配列へ入れる! }
30.
控えめに言って 面倒😩
31.
テキスト 高階関数を使った場合 ▸ 高階関数(今回はmap)を使うと次のように書くことができま す // 消費税率 let
taxRate = 0.08 // 値段のリスト let prices: [Double] = [10000, 9800, 34570, 29800, 114514]
32.
テキスト 高階関数を使った場合 ▸ 高階関数(今回はmap)を使うと次のように書くことができま す // 消費税率 let
taxRate = 0.08 // 値段のリスト let prices: [Double] = [10000, 9800, 34570, 29800, 114514] let newPrices = prices.map { $0 * taxRate } // 完成!
33.
34.
短い!😳
35.
テキスト 短い!😳 ▸ 高階関数を使うととても簡潔にかけます ▸ 今回使ったmapという高階関数は配列の中身に順番に受け 取った処理を適用し、新しい配列を生成する関数です ▸
{ $0 * taxRate } の部分が配列の中身全てに適用され、その結 果が新しい配列となります ▸ 高階関数を使うことで余計なコードを省き、どんな処理を したいのか?という部分に集中できます
36.
ちょっと待って! (TWITTER並感)
37.
そもそも関数って なんだっけ?🤔