×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

Give an example of how the 'break' keyword can be used to exit a loop prematurely.

by EITCA Academy / Tuesday, 08 August 2023 / Published in Web Development, EITC/WD/PMSF PHP and MySQL Fundamentals, PHP procedures and functions, Continue and break, Examination review

The 'break' keyword in PHP is used to prematurely exit a loop, whether it is a 'for', 'while', or 'do-while' loop. When encountered, the 'break' statement terminates the loop immediately, and the program execution continues with the next statement after the loop. This can be particularly useful when you want to stop the execution of a loop based on a certain condition, without waiting for the loop to naturally reach its end.

Let's consider an example to illustrate the usage of the 'break' keyword in a loop. Suppose we have an array of numbers, and we want to find the first occurrence of a number that is divisible by 5. We can use a 'foreach' loop to iterate over the array, and when we find the desired number, we can break out of the loop.

php
$numbers = [2, 7, 10, 15, 21, 25, 30];

foreach ($numbers as $number) {
    if ($number % 5 == 0) {
        echo "Found a number divisible by 5: $number";
        break;
    }
}

In this example, the 'foreach' loop iterates over each element in the '$numbers' array. The 'if' condition checks if the current number is divisible by 5 using the modulo operator (%). If the condition is true, the program executes the 'echo' statement, displaying the number that meets the criteria. Following that, the 'break' statement is encountered, causing the loop to terminate immediately.

If we run this code, the output will be: "Found a number divisible by 5: 15". As soon as the loop encounters the number 15, which is divisible by 5, the loop is exited, and the program continues with the next statement after the loop.

The 'break' statement can also be used with nested loops. In such cases, the 'break' statement only exits the innermost loop it is contained in. If you want to exit multiple nested loops simultaneously, you can use labeled loops and specify the label in the 'break' statement.

The 'break' keyword in PHP is a powerful tool to prematurely exit a loop. It allows you to control the flow of your program by terminating the loop based on specific conditions. Whether used in a simple loop or within nested loops, the 'break' statement provides flexibility and control over the execution of your code.

Other recent questions and answers regarding Continue and break:

  • How does the 'continue' keyword affect the flow of a loop in PHP?
  • What is the purpose of the 'continue' keyword in PHP loops?
  • How does the 'break' keyword affect the flow of a loop in PHP?
  • What is the purpose of the 'break' keyword in PHP loops?

More questions and answers:

  • Field: Web Development
  • Programme: EITC/WD/PMSF PHP and MySQL Fundamentals (go to the certification programme)
  • Lesson: PHP procedures and functions (go to related lesson)
  • Topic: Continue and break (go to related topic)
  • Examination review
Tagged under: Break Statement, Control Flow, Loops, MySQL, PHP, Web Development
Home » Continue and break / EITC/WD/PMSF PHP and MySQL Fundamentals / Examination review / PHP procedures and functions / Web Development » Give an example of how the 'break' keyword can be used to exit a loop prematurely.

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (105)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.

Eligibility for EITCA Academy 80% EITCI DSJC Subsidy support

80% of EITCA Academy fees subsidized in enrolment by

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2025  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP
    Chat with Support
    Chat with Support
    Questions, doubts, issues? We are here to help you!
    End chat
    Connecting...
    Do you have any questions?
    Do you have any questions?
    :
    :
    :
    Send
    Do you have any questions?
    :
    :
    Start Chat
    The chat session has ended. Thank you!
    Please rate the support you've received.
    Good Bad