[thelist] prev and next [ Anthony Baratta]

Ornstein, Ian IanOrnstein at NC.SLR.com
Mon Jul 9 15:03:47 CDT 2001


<SoapBox>
    There are two predominate styles in writing C 
    ( and by extension, JavaScript). The first one
    I refer to as K & R for Kerrigan and Richie who authored
    the defining book for C about 20 years ago.
    The format they employed saves vertical space on the
    page ( and screen ) by writing their opening braces at the
    end of a line.

    The alternative style is called ANSI C because the American
    National Standards Institute published a standard ( I'm just
    guessing here ) arround 1990. It brought together the various
    C dialects so more of the code would be source compatible.

    [The dialects divergied when University of California at Berkley
      started a different distribution from the original authors at
      Bell Telephone Laboratories. Perhaps you have heard of BSD?
      aka Berkley Software Distribution}

    Anyway the ANSI C recommend that opening and closing braces
    be at the same indent level. 
    I find this much more readable even though most editors have a 
    fence matching feature to let you check the other end of the brace.

    It bothers me that most JavaScript writers don't use this newer format.
</SoapBox>
    Returning to your question: it appears that you have cut off part of the
    suggested code.  It is more easily seen if I reformat the code from:

var maxPages = 5;
var ind=0
 function next(){
 if(ind<thepages.length && thepages.length!>maxPages){
 top.main.location=thepages[ind+1]
 ind++
  }
}

to 
var maxPages = 5;
var ind=0

function next()
{
    if(ind<thepages.length && thepages.length!>maxPages)
    {
        top.main.location=thepages[ind+1]
        ind++
    }
}
AND this 
function next(){
for(i=0; i<thepages.length-2; i++){
top.main.location.href=thepages[i]
}
To this
function next()
{
    for(i=0; i<thepages.length-2; i++)
    {
        top.main.location.href=thepages[i]
    }
// you will now notice that the function next()
has no closing brace "}" 
It is much easier to spot these kinds of errors
if the braces are veritcally alligned and you
use a consitand indent of four spaces.

HTH
- IanO -
-----Original Message-----
From: Kevin Raleigh [mailto:krr at ix.netcom.com]
Sent: Monday, July 09, 2001 12:53 PM
To: thelist at lists.evolt.org
Subject: [thelist] prev and next [ Anthony Baratta]


I appreciate your quick response.

I tried the approach you mention but haven't been able to make it
work.

var maxPages = 5;
var ind=0
 function next(){
 if(ind<thepages.length && thepages.length!>maxPages){
 top.main.location=thepages[ind+1]
 ind++
  }
}

the error as reported: expected closing bracket
if(ind<thepages.length && thepages.lengt  "closing bracket" h!>maxPages){
How can it expect a closing bracket in the middle of the work length?


Also tried this but it loads page 3 and then stops
function next(){
for(i=0; i<thepages.length-2; i++){
top.main.location.href=thepages[i]
}




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I actually have one other item that is got me bugged.
This link points at two versions of the same code.

The first example won't navigate back to page one but the
second one will.
The only difference that I can see is that the folders are constructed
different. One is using a flat folder setup and the other is using
folders three deep. The easy answer is to put all the files into one
folder, But the number of files involved makes it exceedingly difficult
to keep track of everything.

I setup the first folder two emulate my websites layout for one demo and
in the second demo I used a flat file approach. No Folders!

Can you tell me why one works and the other doesn't?
http://home.netcom.com/~krr/navigation/

If you can add any insight I would really appreciate it!

Thank You
Kevin

> Message: 6
> Date: Sat, 07 Jul 2001 23:05:18 -0700
> To: thelist at lists.evolt.org
> From: Anthony Baratta <Anthony at Baratta.com>
> Subject: Re: [thelist] prev and next
> Reply-To: thelist at lists.evolt.org
>
> All you need is a little "state" checking. If int is = 0 (or one), don't
to
> previous. If int is greater than (or equal to) the total number in the
> array, don't do next. You can also replace the image src with a space.gif.
> ---
> Anthony Baratta
> President
> Keyboard Jockeys







More information about the thelist mailing list