DRY when assigning new value each loop

Considering a function query_item that either returns an object to be processed or null if nothing is to be processed anymore.

let item = query_item();
while(item !== null){
    process(item);
    item = query_item();
}

Clearly, this is a small violation of DRY (Don’t repeat yourself), mostly mitigated by having query_item() as a dedicated function.

I am aware that in this simple case, clarity is much more important than preventing repetition.

Nevertheless, is there a way to write a loop like this without repeating the assignment?

The only thing that I came up with was a for-loop approach, but that has the same repetition and is – in my eyes at least – a little harder to read.

for(let item = query_item();
    item !== null;
    item = query_item()
){
    process(item);
};

Answer

This is the standard scenario where one would use an assignment inside the while condition:

let item;
while (item = query_item()) {
    process(item);
}

or possibly, if you want to be explicit:

let item;
while ((item = query_item()) !== null) {
    process(item);
}

You also can use a for loop with the same approach, which also gives you block scope for let:

for (let item; item = query_item(); ) {
    process(item);
}