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 8409663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:58:22+00:00 2026-06-09T23:58:22+00:00

switch ($var) { case 0: // Do something… break; case 1: // Do something…

  • 0
switch ($var) {
    case 0:
        // Do something...
        break;
    case 1:
        // Do something...
        break;
    default:
        // Do something...
        break;
}

I’ve seen some people use break at the end of the default case. Since the default case is the last case that’s executed when triggered, is there any need to have a break there? I’m guessing it’s just done out of common practice or is there another reason?

  • 1 1 Answer
  • 0 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-06-09T23:58:24+00:00Added an answer on June 9, 2026 at 11:58 pm

    There’s no reason its required so long as the default is at the end of the switch statement. Note that the default doesn’t need to be the last case: http://codepad.viper-7.com/BISiiD

    <?php
    $var = 4;
    switch($var)
    {
        default:
            echo "default";
            break;
        case 4:
            echo "this will be executed";
            break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that switch / select statements break automatically after every case. I am
I have this code: _trackit: function(){ for(var key in this.items.sublinks){ switch(key){ case 'shoes': for(var
I have a switch case statement that doesn't work. I've checked the input, it's
<?php $var = 0; switch($var) { case a: echo I think var is a;
I've recently learned that python doesn't have the switch/case statement. I've been reading about
How do people switch fixed elements when scrolling down the page? Here's a perfect
How do I switch the database that my entity model is connected to at
If I switch GL_QUADS to GL_TRIANGLES and remove the last point, the triangle renders
I have a javascript function that, in most cases, needs to do something with
The javascript parameter Step should trigger a switch-case function in php. If Step is

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.