codeloverfromkz
codeloverfromkz

Reputation: 21

Can't initialize variables in for loop in C in VSCODE

I think something wrong with my VSCode, since i can't initialize varibles in loops in C For instance:

    #include <stdio.h>

    int main(){
     for(int i = 0; i < 5; i++){
      printf("%i", i);
     }
     }

It gives compile error How can I fix it? Thanks in advance

Upvotes: 0

Views: 351

Answers (1)

JBahn77
JBahn77

Reputation: 74

either declare i prior to the for loop or compile with "-std=c99"

#include <stdio.h>

int main(){
    int i = 0;
    for(i = 0; i < 5; i++){
    printf("%i", i);
    }
 }

 

Upvotes: 1

Related Questions