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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:53:57+00:00 2026-06-04T20:53:57+00:00

I have below code. I wrote a for loop and inside that I have

  • 0

I have below code. I wrote a for loop and inside that I have switch statement. The switch has two cases and if i==someOtherValue is true then entire loop should exit.

for (//iterate over elements){
    int i = someValueTakenFromLoop;
    if(i==someOtherValue){

        switch(i){
            case 5:
                //some logic
                break;
            case 6:
                //some logic
                break;
         }
     }
 }

While iterating if i==someOtherValue is true then it should exit the loop. Do i need to keep break statement out side switch?.

    for(//iterate over elements){
        int i = someValueTakenFromLoop;
        if(i==someOtherValue){
            switch(i){
                case 5:
                    //some logic
                    break;
                case 6:
                    //some logic
                    break;
            }
            break;
         }
     }

Thanks!

  • 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-04T20:53:58+00:00Added an answer on June 4, 2026 at 8:53 pm

    Yes,

    When you break inside switch control just comes out of switch but not from the outside loop, so you will have to break outside switch again to break out of the loop, or else use labeled loop, but in case you use labelled code please make them capitalized for better readability, so that they stand out and can be read clearly, though Java convention suggests to use camel casing.

    1

    for(...) {
          switch(...) {
             break; // this will break from switch
          }
          if(condition) {
             break; // this will break from for loop
          }
       }
    

    2

    OUTERLOOP:
    for(...){
       switch(...){
           break OUTERLOOP;       
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below code. if query is executed without exception then true should return,
I have wrote the code below which was taken from Java How to program
I have this perl code below, basically want to loop through these 2 files.
I have the code below. I would like to write all new data line
I have below code. <table> <tr> <td class=bgimg valign=middle width=10% title=some title nowrap> <img
i have below code and cant check if condition ... how can i solve
I have below code in html. <li class=selected runat=server id=lihome><a href=/ISS/home.aspx title=Home><span>Home</span></a></li> Now I
I have below code behind in c# if (Session[cmpDictionaryTitle]!= null) { downloadLinks.Text += @<li><a
I have below code to insert a style into DOM (there is a use
I have below code.The logic here is if HostList conatains any blanck entry it

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.