実際にswitchステートメントでキーワードを使用できることに気づきcontinue
ましたが、PHPでは期待どおりに機能しません。
PHPで失敗した場合、他にいくつの言語でも失敗することを誰が知っていますか?言語を頻繁に切り替える場合、コードが期待どおりに動作しないと、これが問題になる可能性があります。
continue
それでは、switchステートメントでの使用を避けるべきですか?
PHP(5.2.17)が失敗します:
for($p = 0; $p < 8; $p++){
switch($p){
case 5:
print"($p)";
continue;
print"*"; // just for testing...
break;
case 6:
print"($p)";
continue;
print"*";
break;
}
print"$p\r\n";
}
/*
Output:
0
1
2
3
4
(5)5
(6)6
7
*/
C ++は期待どおりに機能しているようです(forループの最後にジャンプします):
for(int p = 0; p < 8; p++){
switch(p){
case 5:
cout << "(" << p << ")";
continue;
cout << "*"; // just for testing...
break;
case 6:
cout << "(" << p << ")";
continue;
cout << "*";
break;
}
cout << p << "\r\n";
}
/*
Output:
0
1
2
3
4
(5)(6)7
*/