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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:34:38+00:00 2026-06-11T23:34:38+00:00

I’m using a for loop, and it needs a return a String every time

  • 0

I’m using a for loop, and it needs a return a String every time through the loop, but using “return” breaks the loop and Eclipse throws up an “Unreachable Code” error. Any suggestions

  • 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-11T23:34:40+00:00Added an answer on June 11, 2026 at 11:34 pm

    I think your logic is broken

    for (int counter = 0; counter < possibleAnswers.length; counter++){
        // This condition will be meet immediately because 0 is less then 25...
        if (counter < 25){
            return alpha[counter] + ": " + possibleAnswers[counter] + "\n";
        }
        // Meaning it is impossible for the program to ever reach this line...
        if (counter >= 26){
            return alpha[26] + a + ": " + possibleAnswers[counter] + "\n";
            a++;
        }
    }
    

    I think you might be better of trying something like…

    StringBuilder sb = new StringBuilder(25);
    for (int counter = 0; counter < possibleAnswers.length; counter++){
        if (counter < 25){
            sb.append(alpha[counter] + ": " + possibleAnswers[counter] + "\n");
        }
        if (counter >= 26){
            sb.append(alpha[26] + a + ": " + possibleAnswers[counter] + "\n");
            a++;
        }
    }
    return sb.toString();
    

    UPDATE working example

    String possibleAnswers[] = new String[30];
    String alpha[] = new String[30];
    
    for (int index = 0; index < 30; index++) {
        possibleAnswers[index] = "Happy " + index;
        alpha[index] = Integer.toString(index);
    }
    
    int a = 0;
    
    StringBuilder sb = new StringBuilder(25);
    for (int counter = 0; counter < possibleAnswers.length; counter++) {
        if (counter < 25) {
            sb.append(alpha[counter]).append(": ").append(possibleAnswers[counter]).append("\n");
        }
        if (counter >= 26) {
            sb.append(alpha[26]).append(a).append(": ").append(possibleAnswers[counter]).append("\n");
            a++;
        }
    }
    
    System.out.println(sb);
    

    Which outputs

    0: Happy 0
    1: Happy 1
    2: Happy 2
    3: Happy 3
    4: Happy 4
    5: Happy 5
    6: Happy 6
    7: Happy 7
    8: Happy 8
    9: Happy 9
    10: Happy 10
    11: Happy 11
    12: Happy 12
    13: Happy 13
    14: Happy 14
    15: Happy 15
    16: Happy 16
    17: Happy 17
    18: Happy 18
    19: Happy 19
    20: Happy 20
    21: Happy 21
    22: Happy 22
    23: Happy 23
    24: Happy 24
    260: Happy 26
    261: Happy 27
    262: Happy 28
    263: Happy 29
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace

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.