[問題] do while跟我想的不一樣
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a[10];
for(int i=0; i<10; i++)
{
a[i]=i;
}
int j=0;
do{
cout << a[j] << endl;
}while(j<10 && a[j++] !=5);
return 0;
}
我的理解如下:
j=0, cout a[0].
0 < 10 且 a[1] !=5,
所以 cout a[1].
.
.
.
.
.
.
j=4, cout a[4].
4 < 10 且 a[5] == 5,
所以最終只輸出到4. 但顯然我的想法有誤,最終輸出到5。
我哪裡弄錯了哩?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.55.128
→
11/11 23:04, , 1F
11/11 23:04, 1F
→
11/11 23:07, , 2F
11/11 23:07, 2F
推
11/11 23:28, , 3F
11/11 23:28, 3F
→
11/11 23:33, , 4F
11/11 23:33, 4F
→
11/11 23:33, , 5F
11/11 23:33, 5F
推
11/12 00:10, , 6F
11/12 00:10, 6F
→
11/12 00:11, , 7F
11/12 00:11, 7F
→
11/12 00:11, , 8F
11/12 00:11, 8F
→
11/12 00:12, , 9F
11/12 00:12, 9F
→
11/12 00:13, , 10F
11/12 00:13, 10F
推
11/12 00:18, , 11F
11/12 00:18, 11F
推
11/12 00:43, , 12F
11/12 00:43, 12F
→
11/12 00:44, , 13F
11/12 00:44, 13F