KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm just curious what peoples' thoughts are on this topic. Let's say I have an Array of Objects, and I want to loop through them to see if the Objects contain certain values, and if so, I want to stop the loop. Which is better practice - a for loop with a break, or a conditional loop? The pseudo-code in the example I have provided is for argument's sake only (it is also in ActionScript, since that is my primary language of late). Also, I am not looking for best practice ideas on syntax. for loop with break: var i:int; var isBaxterInMilwaukee:Boolean; for (i = 0; i < arrayLen; i++) { if (myArray[i]["name"] == "baxter" && myArray[i]["location"] == "milwaukee") { isBaxterInMilwaukee = true; barkTwice(); break; } } conditional loop: var i:int; var isBaxterInMilwaukee:Boolean; while (!isBaxterInMilwaukee && i < arrayLen) { if (myArray[i]["name"] == "baxter" && myArray[i]["location"] == "milwaukee") { isBaxterInMilwaukee = true; barkTwice(); } i++; }
Tags (comma-separated)
Save Edits
Cancel