Hướng dẫn how does continue work in php? - Làm thế nào để tiếp tục hoạt động trong php?

(Php 4, Php 5, Php 7, Php 8)

continue được sử dụng trong các cấu trúc vòng lặp để bỏ qua phần còn lại của lần lặp vòng lặp hiện tại và tiếp tục thực hiện ở mức đánh giá điều kiện và sau đó bắt đầu lần lặp tiếp theo.

Lưu ý: Trong Php, câu lệnh chuyển đổi được coi là một cấu trúc vòng lặp cho các mục đích của continue. continue hành xử như break (khi không có tranh luận nào được thông qua) nhưng sẽ đưa ra cảnh báo vì đây có thể là một sai lầm. Nếu một switch nằm trong một vòng lặp, continue 2 sẽ tiếp tục với lần lặp tiếp theo của vòng ngoài.: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed) but will raise a warning as this is likely to be a mistake. If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

continue chấp nhận một đối số số tùy chọn cho biết nó có bao nhiêu mức các vòng lặp bao quanh mà nó sẽ bỏ qua đến cuối. Giá trị mặc định là 1, do đó bỏ qua cuối vòng lặp hiện tại.

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>

Bỏ qua dấu chấm phẩy sau continue có thể dẫn đến sự nhầm lẫn. Đây là một ví dụ về những gì bạn không nên làm.

continue0

Người ta có thể mong đợi kết quả là:

Thay đổi cho continue
Phiên bảnSự mô tả
7.3.0 continue trong một switch đang cố gắng hành động như một tuyên bố break cho switch sẽ kích hoạt continue6.continue6.

Jaimthorn tại Yahoo Dot Com ¶

12 năm trước

continue7

continue8

continue9

continue0

continue1

continue2

continue3

continue4

Nikolay Ermolenko

13 năm trước

continue5

continue6

continue7

continue8

Koen ¶

9 năm trước

continue9

rjsteinert.com

11 năm trước

break0

break1

continue4

www.derosetechnology.com

18 năm trước

break3

break4

break5

break6

break7

continue4

Greg tại Laundrymat.tv ¶

17 năm trước

break9

switch0

switch1

switch2

switch3

switch4

switch5

continue4

Tufan dot oezduman tại gmail dot com ¶

15 năm trước

switch7

switch8

continue4

Clau r Jimenez ¶

1 năm trước

continue 20

continue 21

continue 22

continue4

Người đam mê ¶

14 năm trước

continue 24

continue 25

continue4

MPARSA1372 tại Gmail Dot Com ¶

1 năm trước

continue 27

continue 28

continue 29

continue4

Người đam mê ¶

11 năm trước

continue1

continue2

continue4

www.derosetechnology.com

18 năm trước

continue4

continue5

continue6

continue4

Greg tại Laundrymat.tv ¶

17 năm trước

continue8

continue9

10

11

12

13

Người đam mê ¶

14 năm trước

14

MPARSA1372 tại Gmail Dot Com ¶

17 năm trước

15

16

17

continue4

Tufan dot oezduman tại gmail dot com ¶

15 năm trước

19

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
0

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
1

Clau r Jimenez ¶

1 năm trước

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
2

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
3

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
4

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
5

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
6

Người đam mê ¶

17 năm trước

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
7

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
8

foreach ($arr as $key => $value) {
    if (!(
$key 2)) { // skip even members
        
continue;
    }
    
do_something_odd($value);
}
$i 0;
while (
$i++ < 5) {
    echo 
"Outer\n";
    while (
1) {
        echo 
"Middle\n";
        while (
1) {
            echo 
"Inner\n";
            continue 
3;
        }
        echo 
"This never gets output.\n";
    }
    echo 
"Neither does this.\n";
}
?>
9

continue0

continue1

continue2

continue3

continue4

Tufan dot oezduman tại gmail dot com ¶

17 năm trước

continue5

continue6

continue7

continue8

continue9

continue4

PHP tiếp tục làm gì?

Từ khóa tiếp tục được sử dụng để kết thúc lần lặp hiện tại trong A, foreach, trong khi hoặc thực hiện vòng lặp và tiếp tục lặp lại lần lặp tiếp theo.end the current iteration in a for , foreach , while or do.. while loop, and continues to the next iteration.

Làm thế nào để tiếp tục cho công việc vòng lặp?

Trái ngược với tuyên bố Break, tiếp tục không chấm dứt hoàn toàn việc thực hiện vòng lặp, mà thay vào đó: Trong một thời gian, nó nhảy trở lại điều kiện. Trong một vòng lặp, nó nhảy vào biểu thức cập nhật.it jumps to the update expression.

Có tiếp tục làm việc trong foreach PHP không?

Giới thiệu.Câu lệnh tiếp tục là một trong những từ khóa điều khiển vòng lặp trong PHP.Khi luồng chương trình xuất hiện tiếp tục bên trong một vòng lặp, phần còn lại của các câu lệnh trong vòng lặp hiện tại của vòng lặp được bỏ qua và lần lặp tiếp theo của vòng lặp bắt đầu.Nó có thể xuất hiện bên trong trong khi, làm trong khi, cũng như vòng lặp foreach.It can appear inside while, do while, for as well as foreach loop.

Sự khác biệt giữa phá vỡ và tiếp tục trong PHP là gì?

Tuyên bố Break chấm dứt toàn bộ lần lặp của một vòng lặp trong khi tiếp tục bỏ qua lần lặp hiện tại.Tuyên bố Break chấm dứt toàn bộ vòng lặp sớm trong khi việc tiếp tục mang lại lần lặp tiếp theo sớm.. The break statement terminates the whole loop early whereas the continue brings the next iteration early.