Re: Continous Looping of a List

From: Paul Lalli (mritty_at_gmail.com)
Date: 09/25/04


Date: Fri, 24 Sep 2004 19:41:43 -0400

cp wrote:

> My very bad. In my original problem statement, I neglected to mention
> that I need the loop to be continuous. So if the current selected id is
> 9, the functions needs to return 7 and 1. If the current selection is
> 1, it needs to return 9 and 3.
>

The output of my function is identical to the output of your funciton,
including returning the 2nd and last element when given the first. Can
you explain to me what your function does that mine does not?

Did you try to run my function, or are you just making an assumption it
doesn't do what you want?

> In article <KW_4d.173$va.125@trndny03>, Paul Lalli <mritty@gmail.com>
> wrote:
>
>>My version of your function:
>>
>>sub array_nav {
>> my ($val, @ids) = @_;
>> my $pos;
>> for ($pos=0; $pos<=$#ids; $pos++){
>> last if $val == $ids[$pos];
>> }
>> return undef unless $pos < @ids; #error checking
>
>
> Yes. I see what you are doing. however, I was hoping for error checking
> to determine whether the selected id was part of the set Before
> looping. May fault for not stating the problem more clearly.
>

The question here is "why?" Assuming you do have some sort of valid
reason for this, checkout the Perl FAQ:
perldoc -q contained

>
>> my $prev = $ids[$pos-1];
>> my $next = $pos == $#ids ? $ids[0] : $ids[$pos+1];
>> return ($prev, $next);
>>}

Paul Lalli



Relevant Pages

  • Re: help with VBA
    ... Within your loop you determine that you're at ... and know that you need to sort everything on all of the rows from 4 to this ... "indraneel" wrote: ... The first thing to do is to name the ranges you want sorted, ...
    (microsoft.public.excel.worksheet.functions)
  • Re: conciseness is power
    ... (maphash (lambda (normal words) ... (push words anagrams))) ... (loop for word = (read-line s nil) ... (loop for group in anagrams do (setf group (sort group #'string-lessp))) ...
    (comp.lang.lisp)
  • Very odd Sort problem when modifying DGV bound data
    ... I have a DGV that is bound to a DataTable that is loaded during application ... I can sort with all the columns and everything works fine. ... a method that can be invoked from a context menu that will loop through the ... Try and sort the ProductID column. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fastest way to sort 2-D variant arrays?
    ... and then change the FSO loop section to loop through the ... array, and add the elements to the recordset using the AddNew statement. ... How would I write my variant array to the recordset? ... Here is something that I use on an ASP page to sort files by date there ...
    (microsoft.public.vb.general.discussion)
  • RE: [PHP] Sort a while loop ?
    ... Sort a while loop? ... DC> 4 Dave 2345 ... DC> Checked by AVG anti-virus system. ...
    (php.general)

Loading