tagged [loops]
How can I avoid "RuntimeError: dictionary changed size during iteration" error?
How can I avoid "RuntimeError: dictionary changed size during iteration" error? I have a dictionary of lists in which some of the values are empty: At the end of creating these lists, I want to remove...
- Modified
- 2 Feb at 16:23
Changing objects value in foreach loop?
Changing objects value in foreach loop? In one place i am using the list of string in that case the i am able to change the value of the string as code given below, But for object of class i am not ab...
- Modified
- 30 Dec at 12:54
Iterate a certain number of times without storing the iteration number anywhere
Iterate a certain number of times without storing the iteration number anywhere I was wondering if it is possible to perform a certain number of operations without storing the loop iteration number an...
Nested FOR loops: readability & performance
Nested FOR loops: readability & performance I understand nested FOR loops. I understand what they do, and how they do it. But my problem is that they seem horribly unreadable to me. Take this example:...
- Modified
- 11 Jul at 12:21
C# loops: iterating through an array
C# loops: iterating through an array If I have a loop such as below: does the anonymous string array get created once initially, or recreated once for each pass? I believe the former, but collegues ar...
How to get property name and its value?
How to get property name and its value? > [C# How can I get the value of a string property via Reflection?](https://stackoverflow.com/questions/987982/c-sharp-how-can-i-get-the-value-of-a-string-prop...
- Modified
- 23 May at 12:32
Iterate over C# dictionary's keys with index?
Iterate over C# dictionary's keys with index? How do I iterate over a Dictionary's keys while maintaining the index of the key. What I've done is merge a `foreach`-loop with a local variable `i` which...
- Modified
- 2 May at 15:13
Declaring variables inside loops, good practice or bad practice?
Declaring variables inside loops, good practice or bad practice? Is declaring a variable inside a loop a good practice or bad practice? I've read the other threads about whether or not there is a perf...
- Modified
- 9 Jan at 22:19
C#: Nested conditionals vs continue statement
C#: Nested conditionals vs continue statement In using ReSharper recently, it is suggesting I reduce nesting in certain places by inverting `if` conditions and using the `continue` statements. ``` for...
- Modified
- 26 Jul at 19:13
How to split a long array into smaller arrays, with JavaScript
How to split a long array into smaller arrays, with JavaScript I have an array of e-mails (it can be just 1 email, or 100 emails), and I need to send the array with an ajax request (that I know how to...
- Modified
- 25 Oct at 23:18
Is recursion ever faster than looping?
Is recursion ever faster than looping? I know that recursion is sometimes a lot cleaner than looping, and I'm not asking anything about when I should use recursion over iteration, I know there are lot...
- Modified
- 25 Oct at 00:32
Object does not support item assignment error
Object does not support item assignment error In my `views.py` I assign values before saving the form. I used to do it the following way: Now, since the list of variables got a bit long, I wanted to l...
- Modified
- 23 May at 11:54
Problems removing elements from a list when iterating through the list
Problems removing elements from a list when iterating through the list I have a loop that iterates through elements in a list. I am required to remove elements from this list within the loop based on ...
Iterating over ResultSet and adding its value in an ArrayList
Iterating over ResultSet and adding its value in an ArrayList I am iterating over an `ResultSet` and trying to copy its values in an `ArrayList`. The problem is that its traversing only once. But usin...
Loop through columns and add string lengths as new columns
Loop through columns and add string lengths as new columns I have a data frame with a number of columns, and would like to output a separate column for each with the length of each row in it. I am try...
Stop vs Break in Parallel.For
Stop vs Break in Parallel.For I have difficulty to understand `loopState.Stop()` and `loopState.Break()`. I have read MSDN and several posts about it but I am still confused. What I understand is that...
- Modified
- 19 Aug at 13:49
PHP foreach loop through multidimensional array
PHP foreach loop through multidimensional array I have an array: ``` $arr_nav = array( array( "id" => "apple", "url" => "apple.html", "name" => "My Apple" ), array( "id" => "orange",...
- Modified
- 9 May at 08:46
Python : List of dict, if exists increment a dict value, if not append a new dict
Python : List of dict, if exists increment a dict value, if not append a new dict I would like do something like that. ``` list_of_urls = ['http://www.google.fr/', 'http://www.google.fr/', 'ht...
C# foreach loop with key value
C# foreach loop with key value In PHP I can use a foreach loop such that I have access to both the key and value for example: I have the following code: ``` Regex regex = new Regex(pattern); MatchColl...
Batch script loop
Batch script loop I need to execute a command 100-200 times, and so far my research indicates that I would either have to copy/paste 100 copies of this command, OR use a `for` loop, but the `for` loop...
- Modified
- 13 Jan at 09:43
How to tell a lambda function to capture a copy instead of a reference in C#?
How to tell a lambda function to capture a copy instead of a reference in C#? I've been learning C#, and I'm trying to understand lambdas. In this sample below, it prints out 10 ten times. ``` class P...
Is there a "do ... while" loop in Ruby?
Is there a "do ... while" loop in Ruby? I'm using this code to let the user enter in names while the program stores them in an array until they enter an empty string (they must press enter after each ...
Using `continue` keywoard in a switch nest inside a foreach loop
Using `continue` keywoard in a switch nest inside a foreach loop I have the code below (which actually is much longer than you see!) ``` foreach (SensorPair sensor in _sensorPairs) { sensorByte = (b...
- Modified
- 7 Jan at 22:14