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

In Python, is there a way to call a method on every item of an iterable?

Possible Duplicate: Is there a map without result in python? I often come to a situation in my programs when I want to quickly/efficiently call an in-place method on each of the items contained by an iterable. (Quickly meaning the overhead of a…
Thane Brimhall
  • 9,256
  • 7
  • 36
  • 50
3
votes
5 answers

how to get set of three next values from generator in a loop

I have one question because I can not find a solution for my problem. gen is a generator (result of difflib.Differ.compare()): normally by iterating over gen I can read each line. The problem is that on each iteration I need to read the current line…
user1880342
  • 128
  • 10
3
votes
2 answers

Filtering a list of object based on nested type

Lets say I have a class as follows: case class Person( name:String, age:Int, dependents:List[Person] ) Lets say I have the following four people: val p1 = Person("Tom",50,List(p2,p4)) val p2 = Person("Bob",20,List(p3)) val p3 =…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
3
votes
1 answer

Python: Iterating over a string by 2 characters

Let's say I have the following ascii hex string "4a65737573". How do I now iterate over it, wrapping a fixed amount of characters, but always incrementing by 2. i.e. 4a65, 6573, 7375...
Dark
  • 803
  • 2
  • 8
  • 23
3
votes
2 answers

How is for...in implemented in JavaScript?

I saw a question about the iteration order of for...in statements, and warning that the order cannot be trusted. How is the iteration and tracking of the current and visited nodes done internally, and how does it differ among JavaScript engines?
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
3
votes
2 answers

Efficient method to check for matrix stability in CUDA

A number of algorithms iterate until a certain convergence criterion is reached (e.g. stability of a particular matrix). In many cases, one CUDA kernel must be launched per iteration. My question is: how then does one efficiently and accurately…
user2398029
  • 6,699
  • 8
  • 48
  • 80
3
votes
2 answers

QDirIterator iteration order

My application is using QDirIterator to iterate through .jpg images in a folder. The are named page0, page1, page2 ... page10, page 11... and so on. The problem is that it is searching the files in the order page0, page1, page10, page11 and so on.…
Ole Henrik Skogstrøm
  • 6,353
  • 10
  • 57
  • 89
3
votes
1 answer

Can I make this iterative process recursive in scheme?

I have this iterative process in Scheme. (In fact I don't really know what kind of process it really is) (define (contains-double? lst) (cond ((or (null? lst) (null? (cdr lst))) #f) ((eq? (car lst) (cadr lst)) #t) (else (contains-double? (cdr…
Arno Moonens
  • 1,163
  • 1
  • 10
  • 19
3
votes
1 answer

Is there something akin to a looping (circular) iterator?

I'm wondering if there's some sort of iterator that can iterate over values in a std::string, starting over from the beginning when it reaches the end. In other words, this object would iterate indefinitely, spitting out the same sequence of values…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
3
votes
1 answer

iteratively deep copy a link list

This is an homework assignment. To change the following recursive deep copy method into an iterative equivalent. I came up close, and need your help to make it right. Recursive implementation: public static StringNode copy(StringNode str) { …
Hank
  • 189
  • 2
  • 7
  • 20
3
votes
3 answers

Lua - why for loop limit is not calculated dynamically?

Ok here's a basic for loop local a = {"first","second","third","fourth"} for i=1,#a do print(i.."th iteration") a = {"first"} end As it is now, the loop executes all 4 iterations. Shouldn't the for-loop-limit be calculated on the go? If…
SatheeshJM
  • 3,575
  • 8
  • 37
  • 60
3
votes
4 answers

C++ iterating a struct

Is it possible to iterate through a struct? For example struct team{ int player1; int player2; int player3; int player4; ... int player99; int size = 99; } then run a for loop to set or access foo 1-4? i guess pseudocode would…
sean
  • 510
  • 7
  • 12
3
votes
3 answers

R prevent "for" loop from reverse iteration

Consider the code below: foo = list("First List", 1, 2, 3) bar = function(x) { cat("The list name is:", x[[1]], "\nThe items are:\n") for (i in 2:length(x)) cat(x[[i]], "\n") } bar(foo) The result will be: The list name is: First…
Ali
  • 9,440
  • 12
  • 62
  • 92
3
votes
2 answers

Iterate through all paths from (0,0,0) to (5,5,5)

I'm sure there's a name or method for what I'm trying to achieve, but as you can judge from the somewhat vague title of this question I just don't know how to word it, and therefore am having trouble searching. Here's what I would like to do: I have…
Pat
  • 343
  • 4
  • 14
3
votes
3 answers

WPF DataGrid: How do you iterate in a DataGrid to get rows and columns?

How can you iterate in the rows and columns of a WPF DataGrid like with a Forms DataGridView in C#? For example, if you have Forms DataGridView you can do something like this: for(int i = 0; i < formsDataGrid1.Rows.Count; i++) { …
Partial
  • 9,529
  • 12
  • 42
  • 57