---
# System prepended metadata

title: 第四周 重複敘述

---

# 第四周 重複敘述 
 for 重複敘述中的迴圈變數的初始值、執行條件、變數迭帶的變化，都是可以視需要而變化

## 例題
```=cpp
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
	COORD point;
	string str, strSpace = "";
	int len;

	cout << "輸入一個字串：";
	cin >> str;

	len = str.length(); 
	for (int i = 0; i < len; i++) 填滿字串strSpace
		strSpace += " ";

	system("cls");  

	for (int posX = 5; posX <= 20; posX++)
	{
		point.X = posX;
		point.Y = 10; 
		
		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
		cout << str; 

		Sleep(200); 

		SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
		cout << strSpace;	
	}

	system("pause");
}

```