Jump to content
  • Advertisement
Sign in to follow this  
wkiffer

Dev-C++ error, "Expected unqualified-id before "for""

This topic is 4402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm using Dev-C++ and I recently ran accross this error message that I can't make heads or tails of. My code so far is:
int x=220;
int y=585;

for (int i=0;i<20;i++)
{
        for(int h=0;h<10;h++)
        {
              myGrid.grid[h].x=x;
              myGrid.grid[h].y=y;
              x+=20;
              }
              x=220;
              y+=20;
} 

The full error message I'm getting is:
expected unqualified-id before "for" 
expected `,' or `;' before "for" 
expected constructor, destructor, or type conversion before '<' token 
expected `,' or `;' before '<' token 
expected constructor, destructor, or type conversion before '++' token 
expected `,' or `;' before '++' token 

It looks like I'm missing a semicolon somewhere but I'm sure I'm not. I've been over this code for a good hour, changing it and whatnot but I haven't been able to fix it. It'll probably just end up being a stupid mistake that I missed, but it's always easier to have someone else's eyes look at it.

Share this post


Link to post
Share on other sites
Advertisement
Uh, that *is* inside a function, right? You can't write "code" "at the top level" like that. You can only declare and initialize (not "assign to") globals, or write classes/functions/etc.

Share this post


Link to post
Share on other sites
Yeah, its inside a function. Maybe this will be one of those things where if you ignore it for a while it'll go away ;)

Share this post


Link to post
Share on other sites
Is this a .cpp file or a .c file? I can't remember for sure, since it's been a while since I programmed in C, but there is (or at least used to be) a restriction where you had to define your local variables at the top of a block of code. I'm not sure if defining them within the initializer part of a for-statement would count as top of the block or not.

Just wild speculation. Given just that code, though, I can't see anything that is obviously wrong, so wild speculation is all I have left. [smile]

One question: Is the error referring to the first for-statement, or the second? Also, did you copy-paste this code into GameDev, or re-type it? Sometimes small subtle mistakes can exist in the original, but when you re-type it to ask for help, you unknowingly fix the problem.

Share this post


Link to post
Share on other sites
I Found it!!!

I should've showed you guys the 10 lines before this also, you guys probably would have caught it. I had a 4 nested if statements above it and at the end of them I accidently put 5 }'s, and the compiler took the last one as the one closing the function, putting this code out in the open which, like Zahlman, pointed out, throws the error.

Thanks for the help guys.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!