Top "For-loop" questions

A for loop is a control structure used by many programming languages to iterate over a range.

Check if object value exists within a Javascript array of objects and if not add a new object to array

If I have the following array of objects: [ { id: 1, username: 'fred' }, { id: 2, username: 'bill' }, { id: 2, username: 'ted' } ] Is there a …

javascript arrays object for-loop foreach
How to use range-based for() loop with std::map?

The common example for C++11 range-based for() loops is always something simple like this: std::vector<int> numbers = { 1, 2, 3, 4, 5, 6, 7 }; …

c++ c++11 for-loop dictionary
C++ for each, pulling from vector elements

I am trying to do a foreach on a vector of attacks, each attack has a unique ID say, 1-3. …

c++ for-loop vector each
Can a for loop increment/decrement by more than one?

Are there other ways to increment a for loop in Javascript besides i++ and ++i? For example, I want to …

javascript for-loop increment
TypeScript for ... of with index / key?

As described here TypeScript introduces a foreach loop: var someArray = [9, 2, 5]; for (var item of someArray) { console.log(item); // 9,2,5 } But isn't …

for-loop foreach typescript
List append() in for loop

In Python, trying to do the most basic append function to a list with a loop: Not sure what i …

python for-loop append
Better way to find index of item in ArrayList?

For an Android app, I have the following functionality private ArrayList<String> _categories; // eg ["horses","camels"[,etc]] private …

java for-loop arraylist
How to make for loops in Java increase by increments other than 1

If you have a for loop like this: for(j = 0; j<=90; j++){} It works fine. But when you have …

java loops for-loop
Django - iterate number in for loop of a template

I have the following for loop in my django template displaying days. I wonder, whether it's possible to iterate a …

django for-loop django-templates
Can I use break to exit multiple nested 'for' loops?

Is it possible to use the break function to exit several nested for loops? If so, how would you go …

c++ for-loop break nested-loops