I am working on a web application and I have run into the following situation.
Dim a as Object
Dim i as Integer = 0
Try
For i=1 to 5
a = new Object()
'Do stuff '
a = Nothing
Next
Catch
Finally
a = Nothing
End Try
Do i need to do the a=Nothing in the loop or will the garbage collector clean ...
What's the best way to break from nested loops in Javascript?
//Write the links to the page.
for (var x = 0; x < Args.length; x++)
{
for (var Heading in Navigation.Headings)
{
for (var Item in Navigation.Headings[Heading])
{
if (Args[x] == Navigation.Headings[Heading][Item].Name)
{
documen...
I have stumbled into several methods of looping in JavaScript, what I like the most is:
for(var i = 0; i < a.length; i++){
var element = a[i];
}
But as tested here (http://www.robertnyman.com/2008/04/11/javascript-loop-performance/), it should probably be written so that the length is only calculated once.
In jQuery there is a ....
I want this method to work for any given number of arguments, i can do that with code generation(with a lot of ugly code), can it be done with recursion? if so how? I understand recursion, but i dont know how to write this.
private static void allCombinations(List<String>... lists) {
if (lists.length == 3) {
for (String s3 : lists[0]...
I have a class that compares 2 instances of the same objects, and generates a list of their differences. This is done by looping through the key collections and filling a set of other collections with a list of what has changed (this may make more sense after viewing the code below). This works, and generates an object that lets me kno...
EDIT: I missed a crucial point: .NET 2.0
Consider the case where I have a list of unsorted items, for the sake of simplicity of a type like this:
class TestClass
{
DateTime SomeTime;
decimal SomePrice;
// constructor
}
I need to create a report-like output, where the total prices for each day are accumulated. There shoul...
Is there a simple Model Checker tool. I am planning to implement a model checker tool which will analyze the code for some of the predefined properties.
...
When I was taking CS in college (mid 80's), one of the ideas that was constantly repeated was to always write loops which test at the top (while...) rather than at the bottom (do ... while) of the loop. These notions were often backed up with references to studies which showed that loops which tested at the top were statistically much mo...
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:
List<string> someList = <some way to init>
foreach(string s in someList) {
<process the string>
}
Other Way:
List<string> someList = <some way to init>
someList.ForEach(delegate(s...
foreach($arrayOne as $value){
do function
}
In the above example, I'd like to pass $arrayOne into a loop, have a function operate that removes some elements of $arrayOne and then have the loop pass over the reduced $arrayOne on the elements that are left until the loop returns false.
Recommendations?
...
I'd like a loop that uses a UInt16 (ushort) to loop through all of its values. However, this doesn't do it:
for( ushort i = 0; i < UInt16.MaxValue; i++ )
{
// do something
}
The problem is that the loop will quit when i == 0xFFFF and not "do something".
If I change the 'for' statement to "for(ushort i = 0; i <= UInt16.MaxValue; i...
Hi
I have a database with a table which is full of conditions and error messages for checking another database.
I want to run a loop such that each of these conditions is checked against all the tables in the second database and generae a report which gives the errors.
Is this possible in ms access.
For example,
querycrit table
id...
I have a variable that is built in loop. Something like:
$str = "";
for($i = 0; $i < 10; $i++) $str .= "something";
If $str = "" is ommitted, I get undefined variable notice, but I thought php auto-declare a variable the first time it sees undeclared one?
How do I do this right?
...
If, like me, you shiver at the site of a While (True) loop, then you too must have thought long and hard about the best way to refactor it away. I've seen several different implementations, none really better than any other, such as the timer & delegate combination.
So what's the best way you've come up with or seen to refactor the dre...
Is there a way to use a foreach loop to iterate through a collection backwards or in a completely random order?
...
Hey!
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 for inner scope variable declaration and for using breaks (instead of gotos.)
Is it good for anything else? Do you use it?
...
I'm trying to convert my sites from CF8 to openBD. I have a cfloop in a site that loops over a date range.
In essence, I want to insert a new record into the db for every 2 weeks (step) of a date range (from and to)
my loop looks like this...
<cfloop
from = "#form.startDate#"
to = "#form.endDate#"
index = "i"
step =...
I have to build an HTML table that shows data for users versus pages visited. It seems klunky to use for and/or foreach loops, but I can't think of anything better. I'm using PHP, but I would assume that this is language agnostic.
...
It's a really basic question but i can't think at the second. How do i set up a loop that asks each time the function inside runs whether to do it again. So it runs it then says something like;
"loop again? y/n"
...
I have been working on a childish little program: there are a bunch of little circles on the screen, of different colors and sizes. When a larger circle encounters a smaller circle it eats the smaller circle, and when a circle has eaten enough other circles it reproduces. It's kind of neat!
However, the way I have it implemented, the pr...