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
2 answers

Storing the contents of a file in an immutable Map in scala

I am trying to implement a simple wordcount in scala using an immutable map(this is intentional) and the way I am trying to accomplish it is as follows: Create an empty immutable map Create a scanner that reads through the file. While the…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
3
votes
2 answers

Different colors for shapes through iterations in Python / Pygame?

I'm new to stackoverflow, but was hoping for a little insight from more advanced programmers. I am switching majors to Computer Science next semester and am taking an intro class learning some beginner's Python programming. I have already finished…
user1333890
3
votes
3 answers

Treating last element specially while iterating a sequence

I find that I often need to treat the last element in the sequence in a special way when iterating it. For example, take the built-in function interpose: > (interpose ", " (range 4)) (0 ", " 1 ", " 2 ", " 3) One way of thinking about this is:…
icyrock.com
  • 27,952
  • 4
  • 66
  • 85
3
votes
3 answers

Surrounding Parenthesis Identifier Java

I would greatly appreciate if you could help me with this in Java. Given two Strings, lets say String A = "(A+B)+(C)" and String B = "((A+B)+(C))" and String C = (A+B) and String D = A+(B+C) and String E = (A+(B+C)) How can I identify if the String…
link_boy
  • 1,025
  • 4
  • 12
  • 23
2
votes
1 answer

Value removed from HashMap during iteration

I have a HashMap with the addresses and the names of the clients that are assigned on a server.When a user signs off everybody receives a message about his departure and then I remove him from the HashMap. The problem is when I iterate the HashMap…
giannis christofakis
  • 8,201
  • 4
  • 54
  • 65
2
votes
2 answers

Storing ordered object/array in localStorage

I have built this chrome extension for our internal portal. There is a form in this portal with just one textarea as an input. Users generally post a set of strings in that form. So my extension stores those values on submit locally and displays the…
Juzer Ali
  • 4,109
  • 3
  • 35
  • 62
2
votes
3 answers

Performance and Linq in iterations

These 2 ways of working both work, but I'm wondering if there's a difference in performance: Dim collection As ItemCollection = CType(CellCollection.Where(Function(i) i.IsPending = True), ItemCollection) For Each item As Item In collection 'Do…
Terry
  • 5,132
  • 4
  • 33
  • 66
2
votes
1 answer

Iteration through OCaml lists with conditional statements

New to OCaml, so all I can come here with is some pseudo. I'd like to write a function which takes in a list, then returns a new list with only odd integers. So, simply iterate through the list, possibly use %2 to find the odd integers, and append…
John Redyns
  • 5,593
  • 6
  • 21
  • 23
2
votes
4 answers

Convert this method from recursive to iterative

I have the following method that is recursive, but I'm getting an StackOverflow because the list is too long. Please, someone with experience could convert this piece of code to iterative? private List FindWayFrom( Node srcNode, …
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
2
votes
1 answer

Iterating over elements in a nested list

To iterate through the elements in a single dimensional array, I can use array = [1, 2, 3, 4, 5, 6] array.each { |x| puts x } Is there any way I to do this for a nested list or a two dimensional array? In this code: two_d_array = [[1,2], [3,4],…
Primal Pappachan
  • 25,857
  • 22
  • 67
  • 84
2
votes
1 answer

Groovy, collating list causes concurrentmodification exception

Still learning the ropes with Groovy, this problem has tripped me up since last night. Not sure why it's throwing concurrentmod exception...(Java 1.6, Groovy 1.8.4) I have a list of keys... [1,2,3,4,5,6,7,8,9,10,11,12,13] I collate the list using a…
raffian
  • 31,267
  • 26
  • 103
  • 174
2
votes
3 answers

java code optimization when iterate list

It is common to iterate list of elements. Check some conditions and remove some elements from list. for (ChildClass childItem : parent.getChildList()) { if (childItem.isRemoveCandidat()) { parent.getChildList().remove(childItem); …
Balconsky
  • 2,234
  • 3
  • 26
  • 39
2
votes
5 answers

Passing a Variable To A Jquery Function

I have a list of items that I'd like to perform the same action on. They all have separate IDs so I want to be able to pass the name of each one to Jquery so that the action is only performed on that ID. For example: one
user988129
  • 73
  • 2
  • 3
  • 10
2
votes
4 answers

How to flatten large loop stacks?

Let's say I wanted to get all the possible combinations of three binary digits, i.e: 0,0,0 0,0,1 0,1,0 0,1,1 1,0,0 1,0,1 1,1,0 1,1,1 I could do something like this: p = [] for a in range(2): for b in range(2): for c in range(2): …
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
2
votes
1 answer

Need to compare difference in two rows?

I need to compare two row with each other and then write the fields that changed into a table. My table: CREATE TABLE dbo.tUserChanges ( cID int IDENTITY (1,1), cChangeDate DateTime, cValueChanged varchar(30), cPreviousValue bit, cCurrentValue…
user1171437
  • 25
  • 1
  • 5
1 2 3
99
100