Some way to declare variable inside while condition?

c++

Solution

for(int c; (c = fgetc(file)) != EOF;) {
    // do something
}

Problem

In C++ you can do this: ``` for (int i = 0 ; i < 10 ; i++) { /* ... */ } ``` And then variable `i` exist only inside body of for statement. Exist some way to do this with while statement? For example it would be nice to do something like this: ``` while ( (int c = fgetc(file)) != EOF ) { /* ... */ } ``` Obviously this does not work. But exist some syntax trick to effectively do this (variable used in while condition and visible only inside body of while statement) ?

Original source

Related problems