0

## for與do迴圈加continue差別

``````for (i=0;i<=10;i++)
{
if (i===3){
continue;
}
console.log(i);
}
//輸出為:0,1,2,4,5,6,7,8,9,10
``````
``````var i=0;
while(i<=10)
{
if(i===3)
{
continue;
}
console.log(i);
i+=1;
}
//輸出為:0,1,2
``````

weiclin iT邦高手 4 級 ‧ 2018-05-19 16:57:20 檢舉

### 3 個回答

2

iT邦大師 1 級 ‧ 2018-05-19 17:01:07

i加到3的時候

``````var i=0;
while(i<=10)
{
if(i===3)
{
//i為3的時候的邏輯
}else{
//i非3的時候的邏輯
console.log(i);
}
i+=1;
}
``````

-日日- iT邦新手 4 級 ‧ 2018-05-19 17:55:54 檢舉

weiclin iT邦高手 4 級 ‧ 2018-05-19 18:18:06 檢舉

i+=1;

``````var i=0;
while(i<＝10)
{
if(i===3)
{
i+=1;
continue;
}
else
{
console.log(i);
i+=1;
}
}
``````

starcity1003
weiclin

while(i<10)

//i為3的時候的邏輯

starcity1003

i+=1;
console.log(i);

``````var i=0;
while(i<＝10)
{
if(i===3)
{
}
else
{
console.log(i);
}
i+=1;
}
``````

log只是紀錄用,為何要忽略?

i+=1;
console.log(i);

i+=1;不能放在前面唷！

``````var i=0;
while(i<＝10)
{
if(i===3)
{
}
else
{
console.log(i);
}
i+=1;
}
``````

(抱歉，檢討中)

-日日- iT邦新手 4 級 ‧ 2018-05-19 22:01:10 檢舉

6
Samと可樂快跑
iT邦研究生 1 級 ‧ 2018-05-19 18:58:40

``````var i = 0;
while(i <= 10) {
if(i !== 3) {
console.log(i);
}
i += 1;
}
``````

while(i<=10)

-日日- iT邦新手 4 級 ‧ 2018-05-19 21:58:59 檢舉

1
wwx
iT邦好手 1 級 ‧ 2018-05-20 12:41:51

``````var i = 0;
do {
if (i === 3)
continue;
console.log(i);
} while (i++ < 10);
//輸出為:0,1,2,4,5,6,7,8,9,10

``````
halawing iT邦新手 2 級 ‧ 2018-05-21 23:52:12 檢舉