How do I approach this problem?

Hi.I am very new to Q, and am working on some challenges that have beenset for me by my instructor.I am stuck on the final task, which requires me to follow a stockmarket index, and work out the daily returns as if investing in eachstock. So essentially I have a table keyed by date and by stock symbolwith closing prices as well as weightings, etc.The problem is is that on occasion a symbol in the index gets switchedout, meaning that although at any one time there are 30 constituentsin the index, there are overall 33 distinct symbols. If a switchoccurs I am meant to close the position in the index, and “re-buy” atthe opening price on that day. Additionally, if the weighting or sharecount changes I need to do the same.I originally used C++ and to me this begs to use a loop, but i don’tthink this is the “Q way”. I was wondering if anyone has any ideas ofhow to approach this? One idea I had was to have a separate errorcolumn, which would be true if a change had appeared, and falseotherwise.I would appreciate any help.