diff --git a/guide/english/c/for/index.md b/guide/english/c/for/index.md index 0a93baf112..7896076671 100644 --- a/guide/english/c/for/index.md +++ b/guide/english/c/for/index.md @@ -99,3 +99,35 @@ for ( ; ; ) { ``` An infinite loop occurs when the condition will never be met, due to some inherent characteristic of the loop. An infinite loop also called an endless loop, and it is a piece of coding that lacks a functional exit so that it repeats indefinitely. + + +## Warning! + +Some older versions of compilers don't support declaration inside the for loop: +```C +#include + +int main () { + + int array[] = {1, 2, 3, 4, 5}; + + for (int i = 0; i < 5; i++) { // The int i = 0 will show you an error on older compiler versions + printf("Item on index %d is %d\n", i, array[i]); + } +} +``` + +You can solve this problem if you declare the variable before: +```C +#include + +int main () { + + int array[] = {1, 2, 3, 4, 5}; + int i; // You declare the variable before the for loop + + for (i = 0; i < 5; i++) { // Now you won't have a problem + printf("Item on index %d is %d\n", i, array[i]); + } +} +```