它跟其他的循环,如while循环,最大的不同,是它拥有一个循环计数器,或是循环变量。这使得For循环能够知道在迭代过程中的执行顺序。----http://zh.wikipedia.org/wiki/For%E8%BF%B4%E5%9C%88(wiki).
比较结果:
#include <iostream>
#include "Sort_algorithm.h"
#include <stdlib.h>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
int L = 1000000000;
clock_t start,end;
double spent_for,spent_while;
start = clock();
for(int i = 0; i < L; i++)
{}
end = clock();
spent_for = (double) (end - start) / CLOCKS_PER_SEC;
start = clock();
while(L--)
{}
end = clock();
spent_while = (double) (end - start) / CLOCKS_PER_SEC;
cout<<"for spent seconds = "<<spent_for<<endl;
cout<<"while spent seconds = "<<spent_while<<endl;
return 0;
}