From: prasad Date: 2008-12-01T21:33:06+09:00 Subject: Re: Control Structures ------=_Part_89482_21485933.1228135113382 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline See if this satisfies you: while (arr = Array.new(4){rand 4}) != [0,1,2,4] p arr end p arr best wishes, Prasad On Mon, Dec 1, 2008 at 5:07 PM, Trent Jones <1337indi@gmail.com> wrote: > G'day all, I'm new to Ruby, been studying Software Engineering at > university and they have been teaching in Java. > > As such, I'm trying to learn as few of the basics by going through and > comverting smoe of the programs I made into Ruby. At the moment, I'm > struggling a bit with the control structures, if-then-else is fine, > switch/case is fine. I'm just a little confused about the for and > while/dowhile loops. > > I'm trying to make a "infinite monkeys" simulation, i.e. initiate an > array of 'x' length and then fill it with random numbers, then check to > see if those numbers are in order, if not, repeat the process. More or > less anyway. > > At the moment I'm using this loop to fill the array: > for num in (0..Integer(a)) > monkey[num]=Integer(rand*5+1) > end > variable 'a' is input by the user to determine how big a sequence, i.e. > 5 numbers in a row. > > Is this the easiest way of doing things? > And then I could use a similar loop to go through and check to see if > each number is in order, but again, is there a simpler way to check? > > Thanks in advance. > TJ > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_89482_21485933.1228135113382--