This is a features I was considering for my own language.
Basically we recognize that in cases like this, we unnecessarily leak information to the outer scope:
int result;
if ((result = do_something()) != ERR_RESULT) {
do_something_with_result(result);
}
Object *obj;
while ((obj = next_object()) != NULL) {
... do stuff ...
}
We could extend the syntax with an declaration:
if (int result; (result = do_something()) != ERR_RESULT) {
do_something_with_result(result);
}
while (Object obj; (obj = next_object()) != NULL) {
... do stuff ...
}
switch (int result; (result = value())) {
...
}
There are a few more possibilities for separator:
while (Object obj : (obj = next_object()) != NULL) {
...
}
while (Object obj, (obj = next_object()) != NULL) {
...
}
while (Object obj | (obj = next_object()) != NULL) {
...
}
while (Object obj :: (obj = next_object()) != NULL) {
...
}
Obviously this is simply about extending what we have in "for" to a more general case.