KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have what I would think is the most common case for processing a queue. I will read off the front of the queue, act on the element (which may cause more elements to be added to the queue), and then loop until the queue is empty. My first instinct was foreach , but no, apparently a queue (even a mutable one) is strict and the foreach loops over all the elements that are in the queue when the iteration starts. I cannot figure out the syntax for a while loop. You'd think that it would be something like while (!q.isEmpty) { var (e, q) = q.dequeue ... } would work, except that I'm redeclaring q . This does work: while (!q.isEmpty) { var (e, q1) = q.dequeue q = q1 ... } but man, does it look wrong ...
Tags (comma-separated)
Save Edits
Cancel