tagged [loops]

Can you 'exit' a loop in PHP?

Can you 'exit' a loop in PHP? I have a loop that is doing some error checking in my PHP code. Originally it looked something like this... This works all

8 Mar at 01:6

do-while loop in R

do-while loop in R I was wondering about how to write do-while-style loop? I found [this post](http://www.mail-archive.com/r-help@r-project.org/msg79174.html): > you can use repeat{} and check conditi...

22 Dec at 14:56

Implementing a loop using a timer in C#

Implementing a loop using a timer in C# I wanted to replace a counter based while loop with the timer based while loop in C#. Example : ``` while(count

2 Jul at 06:34

Calling remove in foreach loop in Java

Calling remove in foreach loop in Java In Java, is it legal to call remove on a collection when iterating through the collection using a foreach loop? For instance: As an addendum, is it legal to remo...

30 Jul at 20:16

Loop through each row of a range in Excel

Loop through each row of a range in Excel This is one of those things that I'm sure there's a built-in function for (and I may well have been told it in the past), but I'm scratching my head to rememb...

8 Jul at 20:13

How to generate different random numbers in a loop in C++?

How to generate different random numbers in a loop in C++? Is it possible to generate different random number, every time loop runs. For example, i have: ``` for (int t=0;t

15 Apr at 11:14

How to break out of multiple loops at once in C#?

How to break out of multiple loops at once in C#? What if I have nested loops, and I want to break out of all of them at once? In PHP, `break` takes an argument f

21 Aug at 18:29

How can I loop through a C++ map of maps?

How can I loop through a C++ map of maps? How can I loop through a `std::map` in C++? My map is defined as: For example, the above container holds data like this: ``` m["name1"]["value1"] = "data1"; m...

1 Jan at 15:36

bash shell nested for loop

bash shell nested for loop I want to write a nested for loop that has to work in the bash shell prompt. nested for loop in Single line command. For example, In the above example, for loop is executed ...

31 Jan at 05:23

What's the fastest way to loop through an array in JavaScript?

What's the fastest way to loop through an array in JavaScript? I learned from books that you should write for loop like this: ``` for(var i=0, len=arr.length; i

23 May at 03:41

Loop through list with both content and index

Loop through list with both content and index It is very common for me to loop through a python list to get both the contents their indexes. What I usually do is the following: I find this syntax a bi...

16 Jun at 19:40

Bash scripting, multiple conditions in while loop

Bash scripting, multiple conditions in while loop I'm trying to get a simple while loop working in bash that uses two conditions, but after trying many different syntax from various forums, I can't st...

23 Feb at 14:50

Prime numbers between 1 to 100 in C Programming Language

Prime numbers between 1 to 100 in C Programming Language I want to print prime numbers between 1 to 100, I write my code like the following but when I run it, it starts printing 3,7,11,17....91 Why no...

6 Dec at 07:2

Difference between foreach and for loops over an IEnumerable class in C#

Difference between foreach and for loops over an IEnumerable class in C# I have been told that there is a performance difference between the following code blocks. and I am no CLR expect but from what...

4 Sep at 17:20

Is there a way to access an iteration-counter in Java's for-each loop?

Is there a way to access an iteration-counter in Java's for-each loop? Is there a way in Java's for-each loop to find out how often the loop has already been processed? Aside from using the old and we...

27 Jan at 12:28

Iterating through the Alphabet - C# a-caz

Iterating through the Alphabet - C# a-caz I have a question about iterate through the Alphabet. I would like to have a loop that begins with "a" and ends with "z". After that, the loop begins "aa" and...

13 Dec at 09:35

Exit from nested loops at desired level

Exit from nested loops at desired level > [Breaking out of a nested loop](https://stackoverflow.com/questions/324831/breaking-out-of-a-nested-loop) How to exit from nested loops at a specific level....

23 May at 10:30

Check for null in foreach loop

Check for null in foreach loop Is there a nicer way of doing the following: I need a check for null to happen on file.Headers before proceeding with the loop In short it looks a bit ugly to write the...

31 Jul at 06:31

How to iterate over a JavaScript object?

How to iterate over a JavaScript object? I have an object in JavaScript: I want to use a `for` loop to get its properties. And I want to iterate it in parts (not all object properties at once). With a...

Looping through files in a folder Node.JS

Looping through files in a folder Node.JS I am trying to loop through and pick up files in a directory, but I have some trouble implementing it. How to pull in multiple files and then move them to ano...

10 Sep at 21:28

Looping through array and removing items, without breaking for loop

Looping through array and removing items, without breaking for loop I have the following for loop, and when I use `splice()` to remove an item, I then get that 'seconds' is undefined. I could check if...

19 Sep at 19:8

For Loop on Lua

For Loop on Lua My assignment is how to do a for loop. I have figured it out in terms of numbers but cannot figure it out in terms of names. I would like to create a for loop that runs down a list of ...

2 Jan at 01:31

foreach vs someList.ForEach(){}

foreach vs someList.ForEach(){} There are apparently many ways to iterate over a collection. Curious if there are any differences, or why you'd use one way over the other. First type: Other Way: ``` L...

1 Nov at 11:18

Replacement for for... if array iteration

Replacement for for... if array iteration I love list comprehensions in Python, because they concisely represent a transformation of a list. However, in other languages, I frequently find myself writi...

12 Sep at 05:14

C++11 reverse range-based for-loop

C++11 reverse range-based for-loop Is there a container adapter that would reverse the direction of iterators so I can iterate over a container in reverse with range-based for-loop? With explicit iter...

29 Aug at 20:51