MATLAB: For and parfor

for loop

Simple question: why does FOR exist at all if we have PARFOR (which performs better and faster)?

Best Answer

That's a thought-provoking question.
"Faster" is not always a requirement in computing. Also, there are many algorithms or simple tasks that require a single thing to be done in sequential order, and cannot be broken apart. A contrived example would be writing bytes to a file. Parallelisation is inappropriate in this case.
I would end up wanting to specify special syntax to parfor that says "only use one thread, and do it in the right order"... But then, that special syntax would be summed up best by the word: for. The for-loop is a basic construct of just about every procedural language out there. If you take it away, you need a damned good reason.
In more simple terms... parfor and for are two different tools that have their own benefits, some of which overlap. Programmers should be able to choose the best tool for the job at hand.