Skip to content

Commit c987147

Browse files
committed
一部のセクション構成と見出しを修正
1 parent f50b611 commit c987147

55 files changed

Lines changed: 550 additions & 609 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

public/docs/cpp/1-types-control/1-0-basic-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-basic-types
2+
id: cpp-types-basic
33
title: 基本的なデータ型
44
level: 2
55
---

public/docs/cpp/1-types-control/2-0-uniform-init.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-uniform-init
2+
id: cpp-types-uniform-init
33
title: '変数の初期化:ユニフォーム初期化 {}'
44
level: 2
55
---

public/docs/cpp/1-types-control/3-0-modifier.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-modifier
2+
id: cpp-types-modifier
33
title: 型を厳密に扱う
44
level: 2
55
---

public/docs/cpp/1-types-control/3-1-const.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-const
2+
id: cpp-types-const
33
title: constによる不変性の保証
44
level: 3
55
---

public/docs/cpp/1-types-control/3-2-auto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-auto
2+
id: cpp-types-auto
33
title: autoによる型推論
44
level: 3
55
---

public/docs/cpp/1-types-control/4-0-console.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-console
2+
id: cpp-types-console
33
title: 'コンソール入出力 (std::cin, std::cout)'
44
level: 2
55
---

public/docs/cpp/1-types-control/5-0-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-control
2+
id: cpp-control
33
title: 制御構文:if, switch, while, for
44
level: 2
55
---
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
---
2-
id: cpp-types-control-if
2+
id: cpp-control-if
33
title: if文
44
level: 3
55
---
66

7-
### if文
7+
### `if`
88

99
`if (条件式)` の条件式は `bool` に変換可能なものである必要があります。C++では `0``false`、それ以外は `true` とみなされます。
10+
11+
```cpp:control-if.cpp
12+
#include <iostream>
13+
14+
int main() {
15+
// --- if文 ---
16+
const int score = 85;
17+
if (score >= 90) {
18+
std::cout << "Grade: A" << std::endl;
19+
} else if (score >= 80) {
20+
std::cout << "Grade: B" << std::endl;
21+
} else {
22+
std::cout << "Grade: C or below" << std::endl;
23+
}
24+
25+
return 0;
26+
}
27+
```
28+
29+
```cpp-exec:control-if.cpp
30+
Grade: B
31+
```
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
---
2-
id: cpp-types-control-switch
2+
id: cpp-control-switch
33
title: switch文とフォールスルー
44
level: 3
55
---
66

7-
### switch文とフォールスルー
7+
### `switch`文とフォールスルー
88

99
`switch` 文は `break` を書かない限り、次の `case` へ処理が流れます(フォールスルー)。意図的なフォールスルーでない限り、`break` を忘れないように注意が必要です。C++17以降では `[[fallthrough]];` 属性をつけることで、「意図的なものである」とコンパイラに伝え、警告を抑制できます。
10+
11+
```cpp:control-switch.cpp
12+
#include <iostream>
13+
14+
int main() {
15+
// --- switch文 ---
16+
const int rank = 2;
17+
std::cout << "Rank " << rank << ": ";
18+
19+
switch (rank) {
20+
case 1:
21+
std::cout << "Gold" << std::endl;
22+
break;
23+
case 2:
24+
std::cout << "Silver" << std::endl;
25+
// breakを忘れるとcase 3も実行される
26+
[[fallthrough]]; // C++17: 意図的に下に流すことを明示
27+
case 3:
28+
std::cout << "(Medalist)" << std::endl;
29+
break;
30+
default:
31+
std::cout << "Participant" << std::endl;
32+
}
33+
34+
return 0;
35+
}
36+
```
37+
38+
```cpp-exec:control-switch.cpp
39+
Rank 2: Silver
40+
(Medalist)
41+
```
Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: cpp-types-control-loop
2+
id: cpp-control-loop
33
title: ループ構文
44
level: 3
55
---
@@ -8,39 +8,10 @@ level: 3
88

99
`while`, `for` も標準的です。
1010

11-
```cpp:control.cpp
11+
```cpp:control-loop.cpp
1212
#include <iostream>
1313

1414
int main() {
15-
// --- if文 ---
16-
const int score = 85;
17-
if (score >= 90) {
18-
std::cout << "Grade: A" << std::endl;
19-
} else if (score >= 80) {
20-
std::cout << "Grade: B" << std::endl;
21-
} else {
22-
std::cout << "Grade: C or below" << std::endl;
23-
}
24-
25-
// --- switch文 ---
26-
const int rank = 2;
27-
std::cout << "Rank " << rank << ": ";
28-
29-
switch (rank) {
30-
case 1:
31-
std::cout << "Gold" << std::endl;
32-
break;
33-
case 2:
34-
std::cout << "Silver" << std::endl;
35-
// breakを忘れるとcase 3も実行される
36-
[[fallthrough]]; // C++17: 意図的に下に流すことを明示
37-
case 3:
38-
std::cout << "(Medalist)" << std::endl;
39-
break;
40-
default:
41-
std::cout << "Participant" << std::endl;
42-
}
43-
4415
// --- 基本的なforループ ---
4516
std::cout << "Countdown: ";
4617
for (int i = 3; i > 0; --i) {
@@ -52,9 +23,6 @@ int main() {
5223
}
5324
```
5425

55-
```cpp-exec:control.cpp
56-
Grade: B
57-
Rank 2: Silver
58-
(Medalist)
26+
```cpp-exec:control-loop.cpp
5927
Countdown: 3 2 1 Start!
6028
```

0 commit comments

Comments
 (0)