do****迴圈
基本架構
do
{
	statements
} while(expression);
do迴圈屬於後判斷迴圈,前面說的while迴圈第一次進入就會先判斷條件是否成立,而do迴圈則是第一次無條件進入(所以至少會執行一次),執行完大括號內的程式碼之後,在判斷條件是否成立來決定要不要跳出,其餘的跟while都一樣。
Source code
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x=0;
	do
	{
		printf("x:%d\n",x++);
	}while(x<10);
	printf("Out\n");
	system("pause");
	return 0;
}

Source code
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int x=1;
	do
	{
		printf("x:%d\n",x);
	}while(x<1);
	printf("Out\n");
	system("pause");
	return 0;
}
執行結果

明明x < 1不成立但還是執行一次,這就是do迴圈跟while最大的不同。