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

Can I do a loop in an MSBuild file?

Currently, I've got he following code in an MSBuild proj file. It's really simple. Define 4 variables and call my MSBuild Task once-per-variable : Code please ~~
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
3
votes
4 answers

Trying to add to dictionary values by counting occurrences in a list of lists (Python)

I'm trying to get a count of items in a list of lists and add those counts to a dictionary in Python. I have successfully made the list (it's a list of all possible combos of occurrences for individual ad viewing records) and a dictionary with keys…
TomR
  • 546
  • 8
  • 19
3
votes
2 answers

Iterating within a function

I've been working on this all day to no avail, I've spent all of about 4 hours researching a possible answer because I like to discover things on my own but I can't seem to move any closer. Im writing a function that takes a string and with this…
3
votes
4 answers

Convert Recursion to Iteration

I'm trying to convert this recursive method to an iterative and I'm a bit stuck as my book doesn't explain it enough. This method searches an array between two values for a specific value and returns the index. Any help or a point in the right…
Tommy
  • 43
  • 2
  • 6
3
votes
5 answers

Vectors in C++ : Why i'm getting so much errors for this simple copy & print program?

i'm trying to use algorithm lib & vector lib to first copy a set of numbers from an array into a vector then printing it using iteration, where is the problem of my code? and one thing is that i chose 2 way to do this iteration first using…
3
votes
2 answers

Iterate on two lists and sync them

I need to iterate on two lists in the following way: Pseudo code: j=1 for i=1 to n: print a[i], b[j] while b[j+1] <= a[i]: j++ print a[i], b[j] For example: a = [1 3 5 7] b = [2 4 9] Desired output: 1 2 3 2 5 2 5 4 7 4 How do…
Yariv
  • 12,945
  • 19
  • 54
  • 75
3
votes
5 answers

Iterative find/replace from a list of tuples in Python

I have a list of tuples, each containing a find/replace value that I would like to apply to a string. What would be the most efficient way to do so? I will be applying this iteratively, so performance is my biggest concern. More concretely, what…
c_harm
3
votes
3 answers

Python: Iterating through a set so we don't compare the same objects multiple times?

So I'm writing a game. Here's how the collision detection works; there's an invisible grid, and objects (or, rather, their references) are added and removed from cells based on where they are. Collision comparisons are only done between objects in…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
3
votes
6 answers

Team size and project iteration length

Do you think that project iteration length is related to project team size? If so, how? What other key factors do you use to recognize correct iteration length for different projects?
dimarzionist
  • 18,517
  • 4
  • 22
  • 23
3
votes
1 answer

How do I get the current sequence number in an iteration in F#?

Consider the following code to demonstrate the question: let sequence = Seq.initInfinite (fun _ -> "Element") Seq.iter (fun _ -> printf "Element no: ?") sequence Is it in any way possible to get the current sequence number (e.g. its rank) to…
Cay
3
votes
2 answers

ruby - lazily iterate through an array

I want to iterate through a part of an array. For example, I try to print every element except the first one: array[1..-1].each {|e| puts e} But array[1..-1] builds a new Array. It's wasteful if array is very huge. Another straightforward…
Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164
3
votes
4 answers

How can I express this Python for loop in Haskell?

Sometimes when I want to use wget, I just end up printing a bunch of lines with Python like so: >>> for i in range(25): ... print "http://www.theoi.com/Text/HomerOdyssey", i, ".html" ... http://www.theoi.com/Text/HomerOdyssey 0…
magnetar
  • 6,487
  • 7
  • 28
  • 40
3
votes
2 answers

Reading directory using file api : how to handle a directory containing 20000-30000 files?

I in the process of writting a simple java program which reads the contents of the directory and print out the names of the files and last modified time . The issue i forsee is , the vault i am reading is pretty huge and there are some case where…
Sudhakar
  • 4,823
  • 2
  • 35
  • 42
3
votes
3 answers

Array.prototype.each = function(callback) { for (var i = 0; i < this.length; i++) callback(this[i]); } - is this ok?

I know it's a matter of taste, but for my taste using for loop each time I want to iterate over array is bad. So I came up with this: Array.prototype.each = function(callback) { for (var i = 0; i < this.length; i++) callback(this[i]); } Now I…
Tad Lispy
  • 2,806
  • 3
  • 30
  • 31
3
votes
2 answers

parallel iterative algorithms for solving Linear System of Equations

Does someone know any library or ready source code of parallel implementation of quick iterative methods (bicgstab, CG, etc) for solving Linear System of Equations for example using MPI or OpenMP?
Nurlan
  • 2,860
  • 19
  • 47
  • 64