• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10886
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Sheriff
Posts: 22798
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to make it a bit safer:
Or using the for-each loop:
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic