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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:04:40+00:00 2026-05-26T12:04:40+00:00

I want to have a for statement that repeats until a given int reaches

  • 0

I want to have a for statement that repeats until a given int reaches a certain value.

For example…

for (int variable = 0; variable < other_variable; variable++) {

The problem with this is that the for statement will never end. It will continue to repeat endlessly. What have I done wrong?

This is my code…

boolean itemexist_check = false;
do {
    int i2 = m_area.m_items.size();

    for (int i = 0; i < i2; i++) {
        String s2 = m_area.m_items.get(i).returnName();
        System.out.println("Checking...");

        if (s2.contains(s)) {
            System.out.println("You take the " + s2 + ".");
            itemexist_check = true;
            player.addItem(m_area.m_items.get(i));
            m_area.m_items.remove(i);
        }
        else {
            //do nothing, repeat loop
        }
    } 
}
while (itemexist_check == false);

In this code, m_area.m_items.size() would return 1, so i2 would be 1.

  • 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-26T12:04:40+00:00Added an answer on May 26, 2026 at 12:04 pm

    There are several possibilities:

    1. you change variable inside the body of the loop;
    2. you change other_variable inside the body of the loop;
    3. other_variable is set to a large value, in which case the loop might take a long time to terminate;
    4. your code never completes a certain iteration of the loop, for example:
      • it’s getting stuck inside a nested loop as suggested by @Eng.Fouad in the comments, or
      • it’s waiting for a lock, or
      • it’s blocking inside an I/O call that never completes (or takes a long time to complete) etc.

    Without knowing the typical value of other_variable and seeing the body of the loop it’s anyone’s guess.

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

Sidebar

Related Questions

I have an if statement that I want to execute if a certain variable
I have to following SQL Statement that I want to conver to LINQ Select
I have an big problem with an SQL Statement in Oracle. I want to
I want to have an If statement that allows me to tell whether I
I have a if statement that I want to break out of. I understand
I have a SQL Statement that works as I want. select COUNT(*), MIN(emailed_to)from email.email_archive
I have a number. I then have an if statement that I want to
I have a series of PHP statements that I only want to run if
I currently have a statement which reads if(Arrays.asList(results).contains(Word)); and I want to add at
I have following LINQ statement and I want to rewrite it using extension methods.

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.