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);
};