Questions tagged [iteration]

Iterations are the successive repetitions in loops such as for, foreach or while. Questions with this tag are often concerned about how to best handle a collection of data.

Wiki

Definition: Iteration is the repetition of a block of statements within a computer program.

In most computer programming languages, an iteration is a process that allows code to be executed repeatedly based on a given Boolean condition. Loops can be thought of as an iteration statements.

Examples

  • for
  • foreach
  • while
  • do while

Tag usage

The tag can be used for all programming related problems in implementing iterative approach to call a programming code repeatedly. The tag can be used in problems in implementing iteration using programming constructs and loops. Tag can also be used with other tags , , and .

Read more

10795 questions
3
votes
1 answer

C++ post operator(s) causing memory leaks

I am implementing a custom iterator for a library, and am overloading the operators ++ and --. My prefix operators for these work perfectly, but my post operators cause memory leaks. avl_iterator& operator++() { _node =…
S Grimminck
  • 516
  • 4
  • 21
3
votes
2 answers

Is iterator.remove() is ROBUST in all cases in java?

As in C++ iterator.remove() is not 100% safe or robust does java guarantees 100% robustness with iterator.remove()?
Ashish Agarwal
  • 113
  • 1
  • 5
3
votes
3 answers

Prefix and postfix ++ on custom iterator doing the same

First of all I'm fairly new to C++ so if this is a beginner coding mistake then I'm sorry. I'm currently working on a graphing class for a homework I got at school. I'm supposed to be able to store edges in a set, array and linked list. As I have…
Vultour
  • 373
  • 4
  • 15
3
votes
1 answer

Iterative version of Binary Tree Search

Basic Tree-search algorithm for searching a node (with value k) in a binary search tree. 'x' denotes the node of the binary search tree. TREE-SEARCH (x, k) if x= NIL or k = key[x] then return x if k < key[x] then return…
halluc1nati0n
  • 893
  • 2
  • 13
  • 18
3
votes
2 answers

word search in java 2d array

I am trying to create a simple word search for a class assignment, and I have managed to figure out how to search east (from left to right) and west(right to left). But I am having trouble trying to figure out how to search south (top to…
3
votes
1 answer

Speed up iteration over Numpy arrays / OpenCV cv2 image

I have 3 numpy arrays of shape > (500, 500). I am trying to iterate over them simultaneously. I have tried two different methods but both of them are slow. Here Ix_Ix_blur, Ix_Iy_blur and Iy_Iy_blur are of the same size. I'm trying to find features…
Froyo
  • 17,947
  • 8
  • 45
  • 73
3
votes
1 answer

How do I avoid flicker in my application?

It's a very common problem every developer faces every now and then, when visual updates may be so rapid and fast that it causes the contents of the form to flicker. I'm currently using a thread to search files and trigger an event to its calling…
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
3
votes
2 answers

Is there a good way to iterate over all the subproperties of a Javascript object?

Given I have a javascript object, is there a way to iterate over all the primitive subproperties? For instance, if I have an object { foo: 17, bar: { a: 2, b: 7 } } I would like to iterate over foo, bar.a, and bar.b. Please keep in…
ferson2020
  • 3,015
  • 3
  • 18
  • 26
3
votes
2 answers

Error renaming a File in a for loop

I have this code in Java. The randomName() function returns a string with (unsurprisingly) a random string. File handle = new File(file); String parent = handle.getParent(); String lastName = ""; for (int i = 0; i < 14; i++) { lastName = parent…
3
votes
1 answer

Iterating through table cells using jQuery and appending to div

I am really confused here.. I am trying to get the values from a table and add those values to the div with class title using append function and .text function. The problem is that when I use the each function the last value in table gets…
designerNProgrammer
  • 2,621
  • 5
  • 34
  • 46
3
votes
2 answers

Javascript. Tricky: Are all array values consistent? (ie: does a = [a,a,a,a]) for any size array

This is rather conceptual, and I'm hoping someone can help. I have a script, that when you insert coordinates (x,y, from 0 -> 800) in to it, it'll return lists of pre-plotted coordinates that are within 3 separate ranges. ie: I enter 200,200. I…
lunchtime
  • 55
  • 5
3
votes
3 answers

Linq FirstOrDefault evaluates predicate each iteration?

If I had a statement such as: var item = Core.Collections.Items.FirstOrDefault(itm => itm.UserID == bytereader.readInt()); Does this code read an integer from my stream each iteration, or does it read the integer once, store it, then use its value…
jduncanator
  • 2,154
  • 1
  • 22
  • 39
3
votes
2 answers

Vector Iteration and Removal in C++

I am trying to iterate over a vector and remove the first occurrence of an object. I keep getting a compile error (using g++), but I am removing it the way stackoverflow answers and other sources suggested removing it. There is probably something…
Sams
  • 197
  • 1
  • 3
  • 14
3
votes
1 answer

Iterating over an array with "holes" in JavaScript

I have got an array from which some items are going to be removed; but some loops are still running on them, so I want to simply skip the places where I remove my objects I know that the syntax for(i in array) should do this because it iterates on…
Rayjax
  • 7,494
  • 11
  • 56
  • 82
3
votes
4 answers

Get first KeyValuePair in a dictionary that has a specific value

I'm writing an app in C#/.NET 4.5 and I have a dictionary defined like this: Dictionary d = new Dictionary(); My integer keys are sequential and unique and, except for empty strings, my values will be unique as well. For…
bmt22033
  • 6,880
  • 14
  • 69
  • 98