The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Compiler is twitching at me. by Llyr2002-08-28 14:28:52
  Two problems: by nhaggin2002-08-28 14:31:00
    Correctness corollary by nhaggin 2002-08-28 14:46:55
Two, actually. You didn't need to declare the loop variable in the first statement of the loop. Doing so is a fairly new feature of ANSI C++ and means the loop variable only has scope within the loop itself, and ceases to exist once the loop ends.

Also, commas can have their place in a for loop. For example, let's say you're doing something requiring looping with a pair of C-style strings. If you wanted to use a for loop to do it, your loop might look something like this:

for (char *first = str1, *second = str2; *first != '\0'; ++first, ++second)
{
// body of loop
}

Here, the comma operator is being used to do two things at once in a single statement: initialize the loop variables, and increment them.

However, this kind of thing can't be done to eliminate loop nesting for multiple-dimensional array (i.e., matrix) processing; you still need the nested loops for correctness.

[ Reply ]
      And a small correction... by nhaggin2002-08-28 14:50:20
        bloodshed dev c++... by Llyr2002-08-28 14:52:50

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)