Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Zero-based indexing option?

  • To: mathgroup at
  • Subject: [mg61655] Re: [mg61621] Zero-based indexing option?
  • From: Murray Eisenberg <murray at>
  • Date: Mon, 24 Oct 2005 21:07:14 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <>
  • Reply-to: murray at
  • Sender: owner-wri-mathgroup at

Are you sure you cannot avoid this procedural way of coding altogether, 
by using instead Nest or NestList?

Matt wrote:
> Hello,
>   I am a C/C++ developer by trade and zero-based indexing is the norm.
> When dealing with a set of objects, if I want to iterate over all of
> them for some reason or another, I'm used to doing something like this:
> unsigned int ii(0);
> while (ii < elementCount)
> {
>   // do something
>   ++ii;
> }
> where elementCount represents the number of elements in a set of
> objects.  In Mathematica, I'm getting into the habit of doing something
> like this:
> iterations = Length[(* of something *)] ;
> iterations++;
> ii = 1;
> While[ii <  iterations, (* do something *); ii++]
> As you can see, I need to initialize my iterator to 1 and in order to
> keep strictly 'less than' semantics, I need to increase the size of my
> object set by one.  This is not a big deal, and if I have no other
> choice, I'll probably settle for setting the iterator to one and using
> 'less than or equal' semantics for the loop constraint so I'm not
> altering the size of the object set.
> However, it would be great if there were a Mathematica option or code
> driven setting that would allow me to use zero-based indexing.  Is
> there such a thing?
> Thanks,
> Matt

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: Zero-based indexing option?
  • Next by Date: Re: Zero-based indexing option?
  • Previous by thread: Re: Zero-based indexing option?
  • Next by thread: Re: Zero-based indexing option?