下面两段C++代码都是用于求1-10的和,其运行结果相同。通常说来,for循环都可以用while循环实现。( )
1 int tnt; 2 int i; 3 4 tnt = 0; 5 for (i = 1; i < 10 + 1; i++) 6 tnt += i; 7 cout << tnt << endl;
1 int tnt; 2 int i; 3 4 tnt = 0; 5 i = 1; 6 while (i <= 10){ 7 tnt += i; 8 i += 1; 9 } 10 cout << tnt << endl;