tagged [loops]

More Pythonic Way to Run a Process X Times

More Pythonic Way to Run a Process X Times Which is more pythonic? ``` count = 0 while count

27 Nov at 15:24

What is the difference between range and xrange functions in Python 2.X?

What is the difference between range and xrange functions in Python 2.X? Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it is faster) or...

26 Nov at 09:17

How do I skip an iteration of a `foreach` loop?

How do I skip an iteration of a `foreach` loop? In Perl I can skip a foreach (or any loop) iteration with a `next;` command. Is there a way to skip over an iteration and jump to the next loop in C#? `...

10 Apr at 09:51

do { ... } while (0) — what is it good for?

do { ... } while (0) — what is it good for? I've been seeing that expression for over 10 years now. I've been trying to think what it's good for. Since I see it mostly in #defines, I assume it's good ...

3 Jun at 23:4

C# enums as function parameters?

C# enums as function parameters? Can you pass a standard c# enum as a parameter? For example: By doing this I hope to retrieve all the names within any given enum. What would the Iteration code look l...

29 Jan at 15:40

c++ exit loop based on keyboard input

c++ exit loop based on keyboard input Is it possible to exit a C++ loop based on keyboard input without actually having to input something each iteration? For instance I feel that this is very easy, b...

30 Mar at 04:24

Performance: List.Count vs checking a stored variable

Performance: List.Count vs checking a stored variable I wonder if this makes any difference: ``` for (int i = 0; i

18 Jun at 13:10

Is there a way to loop through a table variable in TSQL without using a cursor?

Is there a way to loop through a table variable in TSQL without using a cursor? Let's say I have the following simple table variable: Is declaring and using a cursor my only option if I wanted to iter...

15 Sep at 07:18

int object is not iterable while trying to sum the digits of a number?

int object is not iterable while trying to sum the digits of a number? I have this code: but it throws an error: `'int' object is not iterable` I wanted to find out the total by adding each digit, for...

24 Oct at 07:55

While, Do While, For loops in Assembly Language (emu8086)

While, Do While, For loops in Assembly Language (emu8086) I want to convert simple loops in high-level languages into assembly language (for emu8086) say, I have this code: ``` for(int x = 0; x

How to enumerate an enum?

How to enumerate an enum? How can you enumerate an `enum` in C#? E.g. the following code does not compile: And it gives the following compile-time error: > 'Suit' is a 'type' but is used like a 'var

24 Nov at 00:35

How to loop through a plain JavaScript object with the objects as members

How to loop through a plain JavaScript object with the objects as members How can I loop through all members in a JavaScript object, including values that are objects? For example, how could I loop th...

19 Jul at 11:36

C# - How to create a non-detectable infinite loop?

C# - How to create a non-detectable infinite loop? This is just an "I am Curious" question. In C#-in-depth Jon Skeet says about lambda expressions: (Page 233) The footnote then says: (Page 233) I am w...

22 Feb at 19:5

Iterate Multi-Dimensional Array with Nested Foreach Statement

Iterate Multi-Dimensional Array with Nested Foreach Statement I think this might be a pretty simple question, but I haven't been able to figure it out yet. If I've got a 2-dimensional array like so: W...

12 Sep at 12:1

How to create an infinite loop in Windows batch file?

How to create an infinite loop in Windows batch file? This is basically what I want in a batch file. I want to be able to re-run "Do Stuff" whenever I press any key to go past the "Pause". Looks like...

Is there a better way to run a command N times in bash?

Is there a better way to run a command N times in bash? I occasionally run a bash command line like this: To run `some_command` a number of times in a row -- 10 times in this case. Often `some_command...

30 Aug at 01:17

Breaking/exit nested for in vb.net

Breaking/exit nested for in vb.net How do I get out of nested for or loop in vb.net? I tried using exit for but it jumped or breaked only one for loop only. How can I make it for the following:

25 Feb at 11:3

c# parallel foreach loop finding index

c# parallel foreach loop finding index I am trying to read all lines in a text file and planning to display each line info. How can I find the index for each item inside loop? ``` string[] lines = Fil...

21 Feb at 16:33

LINQ: How to skip one then take the rest of a sequence

LINQ: How to skip one then take the rest of a sequence i would like to iterate over the items of a `List`, except the first, preserving the order. Is there an elegant way to do it with LINQ using a st...

12 Mar at 09:47

C# getting all colors from Color

C# getting all colors from Color I want to make a `ComboBox` filled with all the colors from `System.Drawing.Color` But I can't seem to collect all the colors from that collection I've already tried u...

29 Sep at 11:30

For loop to calculate factorials

For loop to calculate factorials Currently I have this set of code and its meant to calculate factorials. ``` int numberInt = int.Parse(factorialNumberTextBox.Text); for (int i = 1; i

16 May at 10:2

How to efficiently remove all null elements from a ArrayList or String Array?

How to efficiently remove all null elements from a ArrayList or String Array? I try with a loop like that But it isn't nice. Can anyone suggest me a better solution? --- Some useful benchmarks to make...

asp.net mvc razor foreach loop adding id to div

asp.net mvc razor foreach loop adding id to div I am trying to add dynamic `id` to `div` inside a `foreach` loop concatenated with value of variable `i`. It throws syntax errors. What might be the iss...

23 Jan at 07:21

C# Iterate over Dictionary sorted by value

C# Iterate over Dictionary sorted by value Is there any way to iterate over a Dictionary, in sorted order, sorted by VALUE not key? I did read abut the "SortedDictionary" object, but sadly, that is so...

14 Jan at 03:39

When should I use IEnumerator for looping in c#?

When should I use IEnumerator for looping in c#? I was wondering if there are any times where it's advantageous to use an IEnumerator over a foreach loop for iterating through a collection? For exampl...

19 Jan at 03:19