Thread: For Loop

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    For Loop

    I'm reading the book by Herbert Schildt called C++ From The Ground Up (3rd Ed). The thing that I dislike about this book, and it's something that stands out, is the fact that in almost every example he uses a For loop. I'm now trying to understand Arrays and Pointers (bloody hard pointers are) and there are For loops scattered all over the place. Are For loops really that useful? Sure, I understand it depends on the situation. I mean when I do things I stay away from For loops and just put a i++ or something at the end of a while or do while loop.

    Maybe it's just my dislike of For loops or ability to find easier to understand ways of doing Herbet's examples but I'd like to hear what actual coders think about this loop.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Well Im not really good with C++ but I like for loops, I find use for them in almost every program I make, although they arent that advanced.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    HS has way too much red ink to ever stand as a credible author of technical subjects IMO.
    It takes a special kind of author to get their own jargon entry.

    The main problem is, readers confuse an easy read with being a good book, but if it teaches you the wrong thing, you're hosed and you don't even know it.

    Arrays and for loops kinda go together
    If you have
    int array[N];

    The natural way of accessing all the elements is
    for ( i = 0 ; i < N ; i++ ) array[i] = i;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    135

    Re: For Loop

    Originally posted by cyberCLoWn
    I'm reading the book by Herbert Schildt called C++ From The Ground Up (3rd Ed). The thing that I dislike about this book, and it's something that stands out, is the fact that in almost every example he uses a For loop. I'm now trying to understand Arrays and Pointers (bloody hard pointers are) and there are For loops scattered all over the place. Are For loops really that useful? Sure, I understand it depends on the situation. I mean when I do things I stay away from For loops and just put a i++ or something at the end of a while or do while loop.

    Maybe it's just my dislike of For loops or ability to find easier to understand ways of doing Herbet's examples but I'd like to hear what actual coders think about this loop.
    It's perfectly normal to find for loops widely used, there's nothing unusual about the fact that Schildt appears to use them a lot in the book you mention; they are indeed very useful. Why is it that you don't like them? Either way, I wouldn't worry, in time you'll probably find that you use them often yourself without even thinking about it.

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    I use for loops everyday. Very useful, esp with data structures.

Popular pages Recent additions subscribe to a feed