🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5205

0-based/1-based arrays

#5205
From: Conor Rafferty
Date: Thu, 03 Mar 1988 04:06
18 lines
904 bytes
Sender:

Reply-To:

Followup-To:


If you have a circular list of length n stored as an array,
the increment-and-wrap operation on the index is
	0-based		       	    1-based
	i = (i+1)%n	 	    i = i%n+1

Walking with a stride of three looks like
        for (j = 0; j < n/3; j++)   for (j = 1; j <= n/3; j++)
            frob( a[3*j]);             frob( a[3*(j-1)+1])


In both cases the 0-based code looks more intuitive to me.
Technical Details
Message-ID: <35@goose.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!nrl-cmf!cmcl2!brl-adm!umd5!uvaarpa!mcnc!decvax!decwrl!labrea!goose!conor
References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!nrl-cmf!cmcl2!brl-adm!umd5!uvaarpa!mcnc!decvax!decwrl!labrea!goose!conor
From: conor@goose.UUCP (Conor Rafferty)
Newsgroups: comp.lang.misc
Subject: 0-based/1-based arrays
Message-ID: <35@goose.UUCP>
Date: 3 Mar 88 04:06:12 GMT
References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu>
Lines: 10
Keywords: 0-based for me
Summary: A concrete reason to prefer one over the other