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

"yield" in Python

I have a function called x that produces a generator like this: a = 5 def x(): global a if a == 3: raise Exception("Stop") a = a - 1 yield a Then in the python shell I call that function like this: >>> print x().next() >>>…
Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
3
votes
1 answer

MongoDB connection reset by peer

I've looked at other solutions to this, such as: Mongodb: Connection reset by peer Mongodb : AutoReconnect, Connection reset by peer But still have this error. I'm trying to load a large GeoJSON file into MongoDB. Here's my code:…
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
3
votes
2 answers

Can every recursive function be rewritten as an iterative function?

I've had this question on my mind for a really long time but I can't figure out the answer. The question is, if does every recursive function have an iterative function that does the same? For example, factorial(n) { if (n==1) { return 1 } …
bodacydo
  • 75,521
  • 93
  • 229
  • 319
3
votes
1 answer

Is it safe to change the iterator dynamically in python?

With python, I need to add members in a list dynamically when the list is iterated over: i = [1,2,3,4,5] for a in i: if a == 1: i.append(100) print a Is it guaranteed to work correctly?
prosseek
  • 182,215
  • 215
  • 566
  • 871
3
votes
3 answers

What is the difference between release and iteration?

The title says What is the difference between release and iteration? Can you explain what the difference is?
streetparade
  • 32,000
  • 37
  • 101
  • 123
3
votes
1 answer

file.each_line can only be called once

I'm having some problems iterating through a file's lines, it seems like i can only use the each_line method once per file file = open_file(path) file.each_line { puts "Q"} puts "--" file.each_line { puts "Q"} puts "--" file.each_line { puts…
Kris Welsh
  • 334
  • 2
  • 14
3
votes
2 answers

gnuplot operation of multicolumn file while iteration

I'm using gnuplot to plot a file with many columns: plot for [i=2:119] "./file.dat" using 1:i w l lt 9 It works fine, BUT I'm not able to edit it in order to print the lines shifted. I'd like to print this, where N is a the shift value plot for…
Cippo1987
  • 59
  • 7
3
votes
4 answers

ConcurrentModificationException while iterating Map

I have the following code below Map buyingItemEnumerationMap = this.toBuyItemEnumeration; for (Entry item : buyingItemEnumerationMap.entrySet()) { if(RandomEngine.boolChance(50)){ //will delete? …
Netorica
  • 18,523
  • 17
  • 73
  • 108
3
votes
3 answers

iterate through data from span tags

I'm trying to select the data from a few span tags I have, the first tag logs in the console, but after that the value is "undefined" The erb that generates the span tag: <%= image.connections.each do |conn| %>
Eric Filkins
  • 329
  • 2
  • 8
  • 23
3
votes
2 answers

Python: How do I iterate over several files with similar names (the variation in each name is the date)?

I wrote a program that filters files containing to pull location and time from specific ones. Each file contains one day's worth of tweets. I would like to run this program over one year's worth of tweets, which would involve iterating over 365…
Worcestershire
  • 151
  • 2
  • 13
3
votes
1 answer

c++ debug assertion failed: map/set iterator not dereferencable

I am getting the following debugging error: Debug Assertion Failed! Program: Path\To\vc\include\xtree Line: 237 Expression: map/set iterator not dereferencable whith these lines of code: for(std::map::iterator it =…
user1950929
  • 874
  • 1
  • 9
  • 17
3
votes
1 answer

Step through range in D

Is there a way to create a step in D ranges? For example, in python, range(1, 10, 2) gives me [1, 3, 5, 7, 9] all odds within 1 .. 10 Is there a way to do this in D using foreach? foreach(x; 1 .. 10) { } I know I can use…
Phil Kurtis
  • 189
  • 1
  • 1
  • 9
3
votes
4 answers

How efficient is Python's 'in' or 'not in' operators, for large lists?

I have a list of over 100000 values and I am iterating over these values and checking if each one is contained in another list of random values (of the same size). I am doing this by using if item[x] in randomList. How efficient is this? Does python…
smac89
  • 39,374
  • 15
  • 132
  • 179
3
votes
3 answers

I can not make my code iterate x -= 1

I am learning Python at MIT 6.00 and stacked making recursion code. Only thing I want to do is just iterate deduct 1 from x, but don't know what to do.. Here is my code def gcdIter(a, b): ''' a, b: positive integers returns: a positive…
3
votes
1 answer

How to make a loop in PowerPoint VBA?

As far as I know, the code below gets a shape from the active window, nudges it a bit, copies the slide and pastes it right after the current one, then turns the pasted slide into an active window, and nudges it again: Sub Test() ' Get the active…
brilliant
  • 2,489
  • 8
  • 26
  • 28