The.Anti.9 The.Anti.9 - 1 month ago 16
C Question

How do I fix "for loop initial declaration used outside C99 mode" GCC error?

I'm trying to solve the 3n+1 problem and I have a

for
loop that looks like this:

for(int i = low; i <= high; ++i)
{
res = runalg(i);
if (res > highestres)
{
highestres = res;
}

}


Unfortunately I'm getting this error when I try to compile with GCC:


3np1.c:15: error: 'for' loop initial
declaration used outside C99 mode


I don't know what C99 mode is. Any ideas?

Answer

I'd try to declare i outside of the loop!

Good luck on solving 3n+1 :-)

Here's an example:

#include <stdio.h>

int main () {

   int a;

   /* for loop execution */
   for( a = 10; a < 20; a = a + 1 ){
      printf("value of a: %d\n", a);
   }

   return 0;
}

Read more on for loops in C here!

Comments