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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:54:02+00:00 2026-06-11T20:54:02+00:00

I have a for loop, but I need it to stop doing anything until

  • 0

I have a for loop, but I need it to stop doing anything until I get a response from the user (aka the user selects left or right). I’m doing this in Android, but I’m not sure of the best way to go about this. The “left” and “right” are images. So I’m listening for left or right to be hit before I keep moving on. I need the loop to go on about 50 times. This is what I have so far.

int testlength = 50;
for (int i = 0; i < testlength; i++) {
    left.setImageResource(R.drawable.left);
    right.setImageResource(R.drawable.right);

    //Stop the for loop and get the input from the user     
}
  • 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-11T20:54:04+00:00Added an answer on June 11, 2026 at 8:54 pm

    You don’t need a loop.

    Just exit the routine once you have 50 responses:

    int count = 0;
    
    String[] responses = new String[50];
    
    left.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            left.setImageResource(R.drawable.left);
            right.setImageResource(R.drawable.right);
    
            responses[count] = "Left";
    
            count++;
    
            if(count == 50)
            {
                // Exit the activity
            }
        }
    };
    
    right.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            left.setImageResource(R.drawable.left);
            right.setImageResource(R.drawable.right);
    
            responses[count] = "Right";
    
            count++;
    
            if(count == 50)
            {
                // Exit the activity
            }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nice dataset loop working, but I need to run another loop
I have text files which I need to remove stop words from them. I
What I need to do is have a loop that I can stop if
I have come across loop-unrolling but what other types of compiler optimization are there
I have a loop that works but not when I try and use it
I have rm -i inside a for loop but when I run it, it
I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
I have a function which I have to loop it a few times but
So I do have this loop, but it stops when it come to function
i have two foreach loop to display some data, but i want to use

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.