tagged [loops]

How to skip a specific position within a for each loop in c sharp?

How to skip a specific position within a for each loop in c sharp? ``` List liste = new List { "A","B","C","D" }; foreach (var item in liste) { System.Diagnostics.Debug.Wri...

30 Oct at 00:2

Get out of multiple loops?

Get out of multiple loops? > [Breaking out of a nested loop](https://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop) I have this code But `break` only "breaks" the most inner

23 May at 12:24

Skip items of a specific type in foreach loop

Skip items of a specific type in foreach loop I have this code for filling datatable from excel file: I h

26 Jan at 10:59

How to update C# hashtable in a loop?

How to update C# hashtable in a loop? I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute....

15 Jun at 20:18

Restart a foreach loop in C#?

Restart a foreach loop in C#? How can I restart a `foreach` loop in C#?? For example: `restart` here is like `continue` or `break` but it restarts the foreach from the begining It is like setting the ...

22 Aug at 06:20

Is using a 'goto' statement bad?

Is using a 'goto' statement bad? After doing some reseach on how to break through a secondary loop ``` while (true) { // Main Loop for (int I = 0; I

29 Jan at 15:11

How can I break out of multiple loops?

How can I break out of multiple loops? Given the following code (that doesn't work): Is there a way to make this work? Or do I have do on

C# Iterate Over DataGridView & Change Row Color

C# Iterate Over DataGridView & Change Row Color I have a datagridview made up of multiple rows and columns. I want to iterate through each row and check the contents of a specific column. If that colu...

3 Jul at 10:43

How to loop on field names of a class

How to loop on field names of a class I have got a class which contains more then 150 fields. i need the name of fields (not value) in an array. because its very hard and not a good approach to write ...

10 Sep at 10:50

DataTable Loop Performance Comparison

DataTable Loop Performance Comparison Which of the following has the best performance? I have seen method two implemented in JavaScript with huge performance gains, however, I was unable to measure an...

17 Oct at 19:44

How do you remove an array element in a foreach loop?

How do you remove an array element in a foreach loop? I want to loop through an array with `foreach` to check if a value exists. If the value does exist, I want to delete the element which contains it...

11 Sep at 22:2

Difference between "while" loop and "do while" loop

Difference between "while" loop and "do while" loop What is the difference between while loop and do while loop. I used to think both are completely same.Then I came across following piece of code: ``...

19 Jul at 08:31

How to add element in List while iterating in java?

How to add element in List while iterating in java? Say I have a List like: While iterating through this list I want to add an element at the end of the list. But I don't want to iterate through the n...

24 Jun at 12:13

bash script use cut command at variable and store result at another variable

bash script use cut command at variable and store result at another variable I have a file with IP addresses as content like this I want to address in that file ``` #!/bin/bash file=config.txt for lin...

19 Jan at 17:50

What's the best way to loop through a set of elements in JavaScript?

What's the best way to loop through a set of elements in JavaScript? In the past and with most my current projects I tend to use a for loop like this: ``` var elements = document.getElementsByTagName(...

1 Oct at 11:57

Indexing my while loop with count parameter in an array

Indexing my while loop with count parameter in an array My function takes an array of ifstream ofjects and the number of ifstream objects as seen below: My problem is I want to use a while loop to rea...

4 Mar at 23:58

What is the most efficient/quickest way to loop through rows in VBA (excel)?

What is the most efficient/quickest way to loop through rows in VBA (excel)? I know VBA in Excel isn't the quickest of things - but I need the most efficient (i.e. quickest) way to loop through a larg...

12 Nov at 02:28

What is the difference between i = i + 1 and i += 1 in a 'for' loop?

What is the difference between i = i + 1 and i += 1 in a 'for' loop? I found out a curious thing today and was wondering if somebody could shed some light into what the difference is here? After runni...

3 Jan at 19:1

How to remove elements from a generic list while iterating over it?

How to remove elements from a generic list while iterating over it? I am looking for a better for working with a list of elements which each need processed and then depending on the outcome are remove...

16 Jan at 12:23

How do I add a delay in a JavaScript loop?

How do I add a delay in a JavaScript loop? I would like to add a delay/sleep inside a `while` loop: I tried it like this: ``` alert('hi'); for(var start = 1; start

3 Mar at 16:19

Java: Array with loop

Java: Array with loop I need to create an array with 100 numbers (1-100) and then calculate how much it all will be (1+2+3+4+..+100 = sum). I don't want to enter these numbers into the arrays manually...

6 Jun at 12:49

How to break nested foreach loop then go to parent foreach loop on c#

How to break nested foreach loop then go to parent foreach loop on c# I have the following code: ``` foreach(// Some condition here) { while (// Some condition here) { foreach (// Some conditi...

How to make a setInterval stop after some time or after a number of actions?

How to make a setInterval stop after some time or after a number of actions? I've created a loop of "changing words" with jQuery by using the code in this answer: [jQuery: Find word and change every f...

27 Aug at 08:20

How do i exit a List<string>.ForEach loop when using an anonymous delegate?

How do i exit a List.ForEach loop when using an anonymous delegate? In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate? Example inputString and ...

24 Aug at 08:31

C# looping through an array

C# looping through an array I am looping through an array of strings, such as (1/12/1992 apple truck 12/10/10 orange bicycle). The array's length will always be divisible by 3. I need to loop through ...

9 Mar at 20:44