---
# System prepended metadata

title: 語法複習--for
tags: [C++複習講義]

---

---
tags: C++複習講義
---

# 語法複習--for

[回目錄](/jHU9MQS5QS-Uvs-ZS6CSxg)

```cpp=
for (初值設定; 執行條件; 回合收尾) 
    重覆內容;
```

::: info
例題1
輸入一整數x，計算 1加到x的和
:::

```cpp=
#include<iostream>
using namespace std;
int main(){
    int sum=0;
    for(int n=1; n<=x; n++){
        sum+=n;
    }
    cout<<sum;
    return 0;
}
```