This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to while loop with the condition being multiple elements of an array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to while loop with the condition being multiple elements of an array?" Watch "how to while loop with the condition being multiple elements of an array?" New topic
Author

how to while loop with the condition being multiple elements of an array?

Johnny Knight
Greenhorn

Joined: Jul 28, 2011
Posts: 1
this is the description of the problem im trying "Random Walkers: suppose that N random walkers, starting in the centre of an N-by-N grid, move one step at a time, choosing to go up down left or right with equal probability at each step. write a program to help formulate and test a hypothesis about the number of steps taken before all cells are touched."

to begin with i am just trying to do it with one walker before chucking loads in there.

so i've got a results array (yes maybe i dont need the grid array for now) and i want to loop until every value of that is true (true is where walker has been) but im just not sure how?



any help would be greatly appreciated. not expecting anyone to solve the problem for me, just wondered if anyone could provide links or tips on how to use multiple array values in loop conditions
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 173

First off, I think you meant for your while() to be an if(). Second, I tend to isolate that kind of looping logic in its own small method.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

And to make it a bit safer:
Or using the for-each loop:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to while loop with the condition being multiple elements of an array?
 
Similar Threads
SoDuko puzzle
breaking out of while loop without condition being met?
Java Code
can't find the logic
Help in Algorithm Construction