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

Idiomatic way to sum multiple vectors in Clojure

Problem: I've got a collection of vectors or lists which I would like to find an idiomatic way to sum onto an existing vector possibly with uneven sized vectors. Contrived example showing the setup: =>(def collated-list [2 3 4 5 6 7 8]) =>(def…
jamiei
  • 2,006
  • 3
  • 20
  • 28
2
votes
2 answers

Are object variables in javascript enumerated in the order they were added?

Possible Duplicate: Elements order - for (... in ...) loop in javascript Assume you have code like this: var a = {} a.a = 1; a.c = 2; a.b = 3; for (var i in a) { console.log(a[i]); } Are 1, 2, and 3 guaranteed to be printed in that order?…
swampsjohn
  • 6,826
  • 7
  • 37
  • 42
2
votes
8 answers

PHP Foreach that repeats itself

I am having a problem with an foreach, that his main propose is to check if a server is up, then access that file, and i'm stuck on an foreach that i want to make it repeat a step. For example i have the following code:
Master345
  • 2,250
  • 11
  • 38
  • 50
2
votes
5 answers

Recursion to Iteration - Scheme to C

Can somewone help me convert this scheme function: #lang racket (define (powmod2 x e m) (define xsqrm (remainder (* x x) m)) (cond [(= e 0) 1] [(even? e) (powmod2 xsqrm (/ e 2) m)] [(odd? e) (remainder (* x…
Thatdude1
  • 905
  • 5
  • 18
  • 31
2
votes
2 answers

How to Iterate from back to front in a diamond-shaped isometric map

Imagine a diamond-shaped isometric map, which is basically a 2D array with (x,y) coordinates and the top cell as the origin, as marked in the cells: I want to iterate through these cells from back to front, in the following order: What's the…
2
votes
2 answers

Python 3: Generate not all permutations, but all non-repetitive combinations of length r?

I'm trying to generate a lazily iterable collection of Vigenere cipher keys of length r. I'm aware of itertools and the permutations() method. However, this generates keys such as ABCD, ABCE, ABCF... but it will never do something like AABC. So…
2rs2ts
  • 10,662
  • 10
  • 51
  • 95
2
votes
2 answers

Implementing a range data type

I have legacy code that is using an enum as a range and iterating through the range. I need to port this to a new platform and make it safer. Note: enums are not safe to iterate through as there may be "holes" or gaps between values. I'm looking…
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
2
votes
1 answer

Better way to print out rows from a datatable in vb.net

I am new to vb.net and I am trying to query a database and print out the records in the row to the console window. I got it to work, but I have a feeling that there is a more concise way to do this. One thing that I am sure is wrong is that I had…
Lance Collins
  • 3,365
  • 8
  • 41
  • 56
2
votes
2 answers

How can I convert a recursive function into iterative function in java?

I am using the following code for parsing of small xml files and it is working successfully. But when I parse huge data files I am getting a stack overflow error. So, I decided to convert this method into an iterative style. Initially when writing…
user1119970
  • 199
  • 2
  • 8
2
votes
2 answers

jQuery .each() to add event handler

I'm having an issue with the .each() function in jQuery, I'm calling these lines when I successfully getAjax and store it in the data variable: $.each(data, function() { $('#modulesList').append("

" + this.code + "

") …
Rich
  • 154
  • 2
  • 11
2
votes
1 answer

How to iterate over array and get key values in PHP

I am trying to figure out how to iterate over an array which is a decoded json string. I would like to create variables for firstname, lastname, etc and then output them to separate rows in a table. Here is an example array. Most results will…
pgtips
  • 1,328
  • 6
  • 24
  • 43
2
votes
3 answers

Ruby: Refactoring a complicated nested-loop method

I'm trying to get rid of duplication in my code. I have a method that populates a checkerboard with checkers: def populate_checkers evens = [0, 2, 4, 6] odds = [1, 3, 5, 7] 0.upto(2) do |x_coord| if x_coord.even? evens.each do…
steve_gallagher
  • 3,778
  • 8
  • 33
  • 51
2
votes
4 answers

Python: Why doesn't this work? (iteration over non-sequence)

I have a dictionary with each key containing a list as a value. And I'm trying to go over all the items in the lists, and let's say I'm trying to print all the items as I go through, I wrote: for item in aDict: for item2 in aDict[item]: …
Dennis
  • 3,506
  • 5
  • 34
  • 42
2
votes
4 answers

Python - Iterating through a large list and putting in queue

I have the for loop code: people = queue.Queue() for person in set(list_): first_name,last_name = re.split(',| | ',person) people.put([first_name,last_name]) The list being iterated has 1,000,000+ items, it works, but takes a couple seconds…
mikeyy
  • 161
  • 1
  • 10
2
votes
2 answers

How do I iterate over a vector of vectors in Clojure?

I have a message with 3 attributes: type, currency and amount. I have a rule with 4 attributes, a destination, a message type, a currency and an amount. I want to go through my rules and find a match to the message on the message type and return the…
David
  • 14,047
  • 24
  • 80
  • 101
1 2 3
99
100