0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[PHP]break文とcontinue文

Posted at

break文

break文とは、ループを強制的に中断する命令で、
for文やwhile文などの繰り返し文の中で、if文と一緒に使うことが多い。

break文
for($i = 1; $i <= 100; $i++){
    if ($i >5){
     break;
    }
    echo $i;
}
//結果:12345

continue文

continue文とは、現在のループだけ抜け出すことができる文。
百聞は一見にしかずだと思うので、詳細は下記参照。

continue文
for($i = 1; $i <= 10; $i++){
    if ($i & 3 == 0){
     continue;
    }
    echo $i;
}
//結果:12457810 (3の倍数の数字だけループから抜け出している)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?