Jump to content

Home

For Loops


Vindikorr

Recommended Posts

I'm getting a syntax error when trying to use for loops, ie:

 

for(int i = 0; i < 5; i++) {
   //do stuff
}

 

This should work should it not? Do they work differently in nwscript for some reason, or are they not supported at all. If so, what other ways could I iterate a command through multiple objects?

 

I don't want to assign it to each object individually because it is messy code, and if there's one thing I hate in this world it's messy code.

Link to comment
Share on other sites

I'm getting a syntax error when trying to use for loops, ie:

 

for(int i = 0; i < 5; i++) {
   //do stuff
}

 

This should work should it not? Do they work differently in nwscript for some reason, or are they not supported at all. If so, what other ways could I iterate a command through multiple objects?

 

I don't want to assign it to each object individually because it is messy code, and if there's one thing I hate in this world it's messy code.

 

 

Your only mistake is a very small one. In nwscript, you can't declare an integer in the for loop itself. It has to be declared before. So your code should work if put like this:

 

void main()
{
   int i;

   for(i = 0; i < 5; i++) {
   //do stuff
   }
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...