Menu

for loops

2002-10-21
2012-09-26
  • Nobody/Anonymous

    What is up with devc++4?  It will not allow me to use for loops at all it always says that the identifies is undeclared.  I can compile my code in the visual stuidio by microsoft, I can compile with the intel compiler, and about 12 others and it works just fine, why won't it work with this one?  Only code I can get to compile is hello world BS.

     
    • Nobody/Anonymous

      Do you have, by any chance, 2 for loops one after another like this?

      for (int i = 0; ...)
      {
      (...)
      }

      for (i = 0; ...)
      {
      (...)
      }

      If so, that's the problem. ANSI C standard says that when a variable is declared as a for loop argument, its scope is limited to that loop ONLY. It is not available outside[before or after] of the loop. So, in the second for loop, you need to redeclare i, since it doesn't exist anymore.

      VC++ has lots of flawed implementation. They probably didn't wanted to add a new specific scope for for loops. Lazy bums... Actually, doing it as the standard says gives an error in VC++: can't redeclare variable i. Just stay away from VC++ =)

      If that's not the problem, I dunno, for loops works fine. Any code snippet to help us?

      -Karhgath

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.