Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:17:01+00:00 2026-05-20T11:17:01+00:00

Could someone please explain, with examples, what is meant by loop break 2 or

  • 0

Could someone please explain, with examples, what is meant by loop break 2 or continue 2 in PHP? What does it mean when break or continue is followed by a number?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:17:02+00:00Added an answer on May 20, 2026 at 11:17 am
    $array = array(1,2,3);
    foreach ($array as $item){
      if ($item == 2) {
        break;
      }
      echo $item;
    }
    

    outputs “1” because the loop was broken forever, before echo was able to print “2”.

    $array = array(1,2,3);
    foreach ($array as $item){
      if ($item == 2) {
        continue;
      }
      echo $item;
    }
    

    outputs 13 because the second iteration was passed

    $numbers = array(1,2,3);
    $letters = array("A","B","C");
    foreach ($numbers as $num){
      foreach ($letters as $char){
        if ($char == "C") {
          break 2; // if this was break, o/p will be AB1AB2AB3
        }
        echo $char;
      }
      echo $num;
    }
    

    outputs AB because of break 2, which means that both statements was broken quite early. If this was just break, the output would have been AB1AB2AB3.

    $numbers = array(1,2,3);
    $letters = array("A","B","C");
    foreach ($numbers as $num){
      foreach ($letters as $char){
        if ($char == "C") {
          continue 2;
        }
        echo $char;
      }
      echo $num;
    }
    

    will output ABABAB, because of continue 2: the outer loop will be passed every time.

    In other words, continue stops the current iteration execution but lets another to run, while break stops the whole statement completely.
    So we can ell that continue is applicable for the loops only, whereas break can be used in other statements, such as switch.

    A number represents the number of nested statements affected.
    if there are 2 nested loops, break in the inner one will break inner one (however it makes very little sense as the inner loop will be launched again in the next iteration of the outer loop). break 2 in the inner loop will break both.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone explain me different situations to use AlarmManager vs Handler with examples please.
Could someone please explain the best way to connect to an Interbase 7.1 database
Could someone please explain? I couldn't find anything on the internet, everything talks about
Could someone simply explain the 3 phases in the Flash Event framework, please? By
Could someone please demystify interfaces for me or point me to some good examples?
Could someone please explain to me what we refer to as life critical information
I am setting up cache in MySQL. Could someone please explain query_cache_min_res_unit ? What
Could someone please tell me which objects types can be tested using Regular Expressions
Could someone please point me toward a cleaner method to generate a random enum
I've recently written this with help from SO. Now could someone please tell me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.