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

  • Home
  • SEARCH
  • 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 1033713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:16:23+00:00 2026-05-16T14:16:23+00:00

I just read this question: Why are different case condition bodies not in different

  • 0

I just read this question: Why are different case condition bodies not in different scope?

It’s a Java question, but my question applies to both C# and Java (and any other language with this scope reducing feature).

In the question, OP talks about how he knows he can manually add in {} to refine the scope of each case in the switch. My question is, how does this work? Does it go up the stack as if it were a method call? If so, what does it do so that it still have access to other variables declared before this scope?

  • 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-05-16T14:16:24+00:00Added an answer on May 16, 2026 at 2:16 pm

    All it’s doing is defining another scope, it’s not translated into a method call. Remember that for locals, the CLR/JVM could decide not to use stack space for them at all, it could choose to utilise processor registers. In some cases, if you’ll excuse the pun, it could decide to optimise out some of the locals by virtue of them not being needed. It could even decide that it can use one register, or memory location “on the stack” for multiple variables as they’re never going to overlap.

    Taking the example from the linked question:

    switch(condition) {
      case CONDITION_ONE: {
        int account = 27373;
      }
      case CONDITION_TWO: {
        // account var not needed here
      }
      case CONDITION_THREE: {
        // account var not needed here
      }
      case CONDITION_FOUR: {
        int account = 90384;
      }
    }
    

    As it stands, that code is functionally identical to:

    int account;
    
    switch(condition) {
      case CONDITION_ONE: {
        account = 27373;
      }
      case CONDITION_TWO: {
        // account var not needed here
      }
      case CONDITION_THREE: {
        // account var not needed here
      }
      case CONDITION_FOUR: {
        account = 90384;
      }
    }
    

    As the account variable is never used in multiple cases, which means it’s an ideal candidate (in this simplistic example ) for using a register or a single space in memory.

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

Sidebar

Related Questions

Yes, this might sound like a newbie question but there's a TWIST! ( And
I read about adjustor thunk from here . Here's some quotation: Now, there is
The two posts below are great examples of different approaches of extracting data from
How would I go about testing the performance benchmarks of different css selectors? I've
When compiling a program containing this particular function, /* * Function read_integer * *
I've read in multiple posts on SO that if users have Javascript disabled, ideally
I recently read Eric Steven Raymond's article How To Become A Hacker and I
I know that by definition AS3 interfaces must be public, and the methods within
Scenario: I have an application that pulls data from a SQL database as well

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.