From: John Joyce Date: 2007-04-29T00:40:08+09:00 Subject: Re: cyclic array On Apr 29, 2007, at 12:10 AM, Josselin wrote: > On 2007-04-28 15:05:48 +0200, Josselin said: > >> I would like to print n elements from an Array in a cyclic way. >> I mean : >> using anArray = [ "a", "b", "c", "d", "e", "f", "g"], I should do : >> anArray.print_cyclic(4, 0) => "a", "b", "c", "d" (first print >> 4 elements starting with the first one) >> anArray.print_cyclic_next => "b", "c", "d", "e" >> anArray.print_cyclic_next => "c", "d", "e", "f" >> anArray.print_cyclic_next => "d", "e", "f", "g" >> anArray.print_cyclic_next => "e", "f", "g", "a" >> anArray.print_cyclic_next => "f", "g", "a", "b" >> anArray.print_cyclic_next => "g", "a", "b", "c" >> ..... >> also in reverse cycle >> anArray.print_cyclic(4, 0) => "a", "b", "c", "d" >> anArray.print_cyclic_previous => "g", "a", "b", "c" >> anArray.print_cyclic_previous => "f", "g", "a", "b", >> what could be the simplest way to do it ? no simple way using >> Array class methods only , >> should I define a class and methods to loop into the array ? any >> existing lib ? if it has been already done why should I rewrite >> it .... >> tfyh >> joss > > Thanks to all of u . As always different ways .. the most difficult > step for a newbie is : where should I start ? > > joss Indeed, as a newbie myself, (forever I think) it is often a bit overwhelming where to start. A common method is to sit down with pen and paper and write out the ideas, brainstorming. Figure out what you want to do. then break each part down into it's components. it doesn't have to be in code yet. That's almost the easy fun part, translating your ideas into code. It really is a design process. Some snippets that you create or do often enough will stick in your mind and you'll be able to apply them quicker with practice. But pseudo code is always a good thing, if you comment it out, it is instant documentation! (if necessary.