loops

Looping through DirectoryEntry or any object hierarchy - C#

I am currently developing an application that use the System.DirectoryServices namespace to create a DirectoryEntry object and loop through the entire hierarchy to collect information. I do not know number of child entries for each DirectoryEntry object in the hierarchy, so I can not create a N number of nested loops to spiders throug...

Testing Bits To Create A String - Is there a better approach?

This code works, but I'm wondering if there is a better way to do it. Basically I need to test bits, and write the appropriate character or characters to a string depending on the state of the bit. The spaces are present because the characters will be displayed with a fixed width font and I'd like to keep them from moving around. C or...

PHP: Retrying a query a set number of times or until success

I'm doing a query to the Alexa API which, for some unknown reason, will occasionally fail. When it does fail, I want to automatically retry the query, up to 10 times. When it fails, the response returned by the API contains the substring AuthFailure. What kind of loop can I do that will retry the query until either the response returne...

How to stop intense Javascript loop from freezing the browser

I'm using Javascript to parse an XML file with about 3,500 elements. I'm using a jQuery "each" function, but I could use any form of loop. The problem is that the browser freezes for a few seconds while the loop executes. What's the best way to stop freezing the browser without slowing the code down too much? $(xmlDoc).find("Object"...

C++ Boost: Any gotchas with BOOST_FOREACH?

This one is for Boost experts. Are there any gotchas or details that the programmer needs to be aware of before he goes in and replaces all his old C/C++ style loops with the lean-and-mean-looking BOOST_FOREACH? (This question is partly derived from here.) ...

Any way to make this working dual core in C#?

Hi, I got a piece of code that loops through the array and looks for the similar and same strings in it - marking it whether it's unique or not. loop X array for I ( loop X array for Y ( If X is prefix of Y do. else if x is same length as Y and it's prefix do something. ) Here is the code to finilize everything for I and c...

How do I ensure all loops finish in the same time in Parallel.For?

Hi, In C# (.NET), I got 2 loops -> A for ... do: { B for do: { something} something that evaluates all "for"s in B loop } I used Parallel.For for the inner loop but the results of those loops varied every time I ran the application. I think it may be a result of Some asynchrounous work, but I am not sure how to be sure ab...

MIPS code broken

I'm working on some MIPS code for my Computer Organizations class, and well I just can't seem to get the MIPS to work correctly and there's not that many MIPS resources online. I'm running the code on PCSPIM. The code is supposed to add 10 to the contents of array2 and store them in array1 and then print array 1. Reworked the code works ...

How do I loop through all layers of Treeview nodes?

Read EDIT 2 first I am trying to set up some way to visually distinguish the nodes in a winform app. For example, alternating colors. Can some one start me down that path? Also, has anyone else had to do that before and how did you do it? Thanks EDIT I had seen the backcolor setting as well(Thank You) but I am having trouble gett...

how to iterate in reverse over a map in c++

I'm having trouble iterating in reverse over a map in gcc c++. When I use a reverse iterator, it seems I can't assign anything to it - the compiler complains. I'm working around it with some awkward code using a forward iterator, but it's not very elegant. Any thoughts? ...

Using Many Arguments Without Duplicating Code

Is there a way to use each of the arguments in this function in sequence without duplicating code? For example, the first time through the loop I'd like to use R, the next time I'd like to use L, etc. valuestruct is set up in the same order as the arguments, so the button method will return the equivalent bool I need for currentbutton ...

How do I loop backwards from SiteMap.CurrentNode to SiteMap.RootNode

I have a simple Sitemap like this from asp:SiteMapDataSource: Page 1 > Page 2 > Page 3 I would like to create foreach loop in C# that generates it instead for using asp:SiteMapPath because I need to add some exceptions to it. Now I cannot figure out how do I loop backwards from SiteMap.CurrentNode to SiteMap.RootNode? ...

Create object name from a string

Say I want to loop through a datareader and create a load of objects of a certain type but using a value from the datareader as the object name e.g. String "string_" + <value from datareader> = new String(); So if I had values temp1,temp2 & temp3 coming out of the datareader I would have 3 new objects of type string e.g. string_temp1...

How do I kill loops in Xcode?

I've been writing/debugging in Xcode and every now and then I accidentally create a loop that I can't stop. Unpasuing debuging and rebuilding (and Go-ing) doesn't help, nor does any of the normal Ctrl-C stuff that I'd use on a normal CLI. The only thing that does the trick is quiting Xcode. Odd question, I know, but any ideas? ...

Javascript closure inside loops - simple practical example

Closures are one of those things which has been discussed a lot on SO, but this situation pops up a lot for me and I'm always left scratching my head what to do. var funcs = {}; for (var i = 0; i < 3; i++) { // let's create 3 functions funcs[i] = function() { // and store them in funcs console.log("My val...

Using While Loop for SQL Server Update

I am trying to become more efficient in my SQL programming. I am trying to run a loop to repeat an update command on field names that only change by a numerical suffix. For example, instead of writing out x_1, y_1, then x_2, y_2 for each update: DECLARE @a INT DECLARE @b VARCHAR SET @a = 1 WHILE @a < 30 set @b = @a BEGIN UP...

Can you get a subset of elements in jQuery as per a grouping amount?

Say I have 5 strong elements, and I want to wrap them in div elements, in groups of 2 using jQuery. Example: <!--original markup--> <strong>I AM STRONG</strong> <strong>I AM STRONG</strong> <strong>I AM STRONG</strong> <strong>I AM STRONG</strong> <strong>I AM STRONG</strong> Becomes <!-- new markup --> <div> <strong>I AM STRON...

What limits the number of nested loops in c?

Edit: For those of you looking for an answer to the question as stated the standard limits the number of nested loops at compile time. At runtime this is a different issue as the only limit would be the size of the program segment. Solved: I was looking too early on in the build process. The c file gets further preprocessing applied t...

Can you embed for loops (in each other) in C++

I am working on a merge sort function. I got the sort down - I am trying to get my merge part finished. Assume that I am learning C++, have cursory knowledge of pointers, and don't understand all the rules of std::vector::iterator's (or std::vector's, for that matter). Assume that num is the size of the original std::vector that have c...

Finding Big-O with multiple nested loops?

int num = n/4; for (int i = 1; i <= num; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { int count = 1; } } } According to the books I have read, this code should be O((n^3)/4). But apparently its not. to find the Big-O for nested loops are you supposed to multiply the bounds? So...