teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

データが5個の場合、Yearが0から始まる場合について、if文とswitch文を使わない書き方を考えました。

2018/02/28 03:00

投稿

mocchisu
mocchisu

スコア7

title CHANGED
File without changes
body CHANGED
@@ -67,4 +67,15 @@
67
67
  print("(result)")
68
68
  }
69
69
 
70
+ ```
71
+
72
+ Yearが0から始まる場合について、if文とswitch文を使わない書き方を考えました。
73
+
74
+ ```Swift
75
+ var Year = 1
76
+ var Weight = 10
77
+
78
+ let WeightAverage = [1, 9, 10, 11, 12, 13]
79
+ let result = WeightAverage[Year]-Weight
80
+ print("(result)")
70
81
  ```

3

データが5個の場合、配列を使った書き方を考えてみました。

2018/02/28 03:00

投稿

mocchisu
mocchisu

スコア7

title CHANGED
File without changes
body CHANGED
@@ -42,4 +42,29 @@
42
42
  let result = 13 - Weight
43
43
  print("(result)")
44
44
  }
45
+ ```
46
+
47
+ データが5個の場合、配列を使った書き方を考えてみました。
48
+ ```Swift
49
+ var Year = 1
50
+ var Weight = 10
51
+
52
+ let WeightAverage = [9, 10, 11, 12, 13]
53
+ if Year == 1 {
54
+ let result = WeightAverage[0] - Weight
55
+ print("(result)")
56
+ } else if Year == 2{
57
+ let result = WeightAverage[1] - Weight
58
+ print("(result)")
59
+ } else if Year == 3{
60
+ let result = WeightAverage[2] - Weight
61
+ print("(result)")
62
+ } else if Year == 4{
63
+ let result = WeightAverage[3] - Weight
64
+ print("(result)")
65
+ } else {
66
+ let result = WeightAverage[4] - Weight
67
+ print("(result)")
68
+ }
69
+
45
70
  ```

2

データが5個のばあいの追記を行いました。

2018/02/28 01:55

投稿

mocchisu
mocchisu

スコア7

title CHANGED
File without changes
body CHANGED
@@ -16,4 +16,30 @@
16
16
 
17
17
  ### 補足情報(FW/ツールのバージョンなど)
18
18
 
19
- データの内容は、「年齢月齢とそれに対応する体重の全国平均値」のような物です。
19
+ データの内容は、「年齢月齢とそれに対応する体重の全国平均値」のような物です。
20
+
21
+
22
+ データが5個の場合を考えました。
23
+
24
+ ```Swift
25
+ var Year = 1
26
+ var Weight = 10
27
+
28
+ switch Year {
29
+ case 1:
30
+ let result = 9 - Weight
31
+ print("(result)")
32
+ case 2:
33
+ let result = 10 - Weight
34
+ print("(result)")
35
+ case 3:
36
+ let result = 11 - Weight
37
+ print("(result)")
38
+ case 4:
39
+ let result = 12 - Weight
40
+ print("(result)")
41
+ default:
42
+ let result = 13 - Weight
43
+ print("(result)")
44
+ }
45
+ ```

1

2018/02/28 01:07

投稿

mocchisu
mocchisu

スコア7

title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,7 @@
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
13
  上の②の部分でどのような方法を使うのが良いのかがわからず、困っています。
14
- データの数が300個くらいあるのですが、全てをコード内で記述して代入する必要があるのか、それとも、何か外部のソフトの様なものと繋げて比較する方法を使った方が良いのでしょうか。
14
+ データの数が600個くらいあるのですが、全てをコード内で記述して代入する必要があるのか、それとも、何か外部のソフトの様なものと繋げて比較する方法を使った方が良いのでしょうか。
15
15
 
16
16
 
17
17
  ### 補足情報(FW/ツールのバージョンなど)