loops

Top 10 Frequencies in a Hash Table with Linked Lists

The code below will print me the highest frequency it can find in my hash table (of which is a bunch of linked lists) 10 times. I need my code to print the top 10 frequencies in my hash table. I do not know how to do this (code examples would be great, plain english logic/pseudocode is just as great). I create a temporary hashing list ...

Cocoa Autoreleasing in loops

(I have read Apple's memory management guide, as well as other memory management help here, but am still confused on the following) What should I do for memory management with convenience methods in a loop? Do I need to explicitly create an autorelease pool and then drain it. Or is it all automagic? e.g. for (i=0; i<numFilePaths; i++...

Tweening a value in Lua

How'd I go about this one? I want to tween a value from one to another in x time. While also taking into account that it'd be nice to have an 'ease' at the start and end. I know, I shouldn't ask really, but I've tried myself, and I'm stuck. Please assume that to cause a delay, you need to call function wait(time). ...

SQL iterating over a list to call EXEC on each item

Attempt to generalize my questions... I want to execute a stored procedure for each result returned by a SELECT statement. Mentally I want to try something like EXEC myStoredProc (SELECT id FROM sometable WHERE cond = @param) More details related to my specific case... I have a SaaS application. I would like to delete a tenant from th...

Practical Uses for jQuery's $().each() method for a presentation

I'm giving a presentation to some coworkers today on how to use jQuery with ColdFusion. This is more of an introduction to jQuery than an advanced session. I'm trying to show how one can loop using jQuery's $().each() method, and in trying to come up with some practical, real world examples and I've drawn a blank. Any suggestions? ...

How can I break out of two nested for loops in objective-c?

I have two for loops nested like this: for(...) { for(...) { } } I know that there is a break; statement. But I am confused about if it breaks both loops or just the one in which it was called? I need to break both ones as soon as I see that it doesn't make sense to iterate more times over. ...

Perl DBI dynamic fetchrow while loops

I'm trying to pass table names to a sub that gets all the field names of that table, stores them into an array, and then uses that array in conjunction with the fetchrow of another sql query to display the data in those fields. Here's the code I have now: Examples of sub calls with table names as the parameter: shamoo("reqhead_rec"); ...

Loop backwards using indices in Python?

I am trying to loop from 100 to 0. How do I do this in Python? for i in range (100,0) doesn't work. ...

Why is it better to use '!=" than '<' in a vector loop? (C++)

Why is it better to use '!=" than '<' in a vector loop? I just can't see the difference. ...

some students asked me why do we need to have loop in a program, and they just won't accept that it is needed

some junior high school students asked me why do we need to have loop in a program, and they just won't accept that it is needed... i already told them if we need to find the average and standard deviation of 100 numbers, we can put the numbers in an array by a loop, and then we can find the average, standard deviation, or print the numb...

ASP.NET Display Selected Items from Listbox in Textbox

I'm trying to display all selected items from a listbox into a textbox. Currently I'm doing the following without success: For i As Integer = 0 To lb_words.ListCount If lb_words.Selected(i) = True Then tb_text.Text &= " Presto" End If Next What should be happening is that for every selected item in my listbox (lb.words...

More compact way to do this?

I have a couple of functions that loop around the surrounding cells of a cell. The grid is contained inside an array. In my code, I have checks to make sure it's not one of the edge cells, as checking an undefined cell causes an error. As such, I have code like this: if(x > 0) { var firstX = x - 1; } else { var firstX = x; } i...

Document not ready for insert after method using a loop with jquery

Is there a way to use a loop to insert separate DIV elements behind each other? Right now I use a loop to do just that, but it doesn't remember the DIV inserted before with the load method. The result is that I only see the last one. The code is meant to show all messages, after it reads the cookie with the db-id when you first arrive ...

Breaking out of nested loops in Java

I've got a nested loop construct like this: for (Type type : types) { for (Type t : types2) { if (some condition) { // Do something and break... break; // Breaks out of the inner loop } } } Now how can I break out of booth loops. I've looked at similar questions, but none concerns Ja...

Java foreach efficiency

I have something like this: Map<String, String> myMap = ...; for(String key : myMap.keySet()) { System.out.println(key); System.out.println(myMap.get(key)); } So is myMap.keySet() called once in the foreach loop? I think it is, but want your opinion. I would like to know if using foreach in this way (myMap.keySet()) has a pe...

jQuery loop though two levels of elements

I have some html that looks like this: <div class="block"> <div id="item1"></div> <div id="item2"></div> </div> <div class="block"> <div id="item3"></div> </div> I'm trying to check to see if my div will contain a specific element. I need to loop though each block, then get each item. What I've got so far $('.block...

Toggle all controls Read-Only on Button Click in WinForm

I want to be able to set a bunch of controls on a Form to Read-Only and back with a button click. Is there a way to loop through them? this.Controls maybe...... Thanks! ...

When to use While or the For in python

Hi, Im currently finding problems in when should I use the While loop or the For loop in python. What looks like is that people prefer using the For loop (less code lines?), is there any specific situation wich I should use one or the other? Its a matter of personal preference? Or the codes I had read so far made me think wrong, and curr...

Need help parsing results from ldap to csv

Hi, I am trying to create a script to generate a csv file with the results of some ldap queries using Net::LDAP but I'm having troubles skipping incomplete lines if one element of the @attributes array is blank. my @attributes = ('cn', 'mail', 'telephoneNumber'); So for example, if a user has no mail listed, or no telephoneNumber li...

selective iteration of array in php

Is there a way of iterating through an array but performing an operation on every other element? ie If I have an array with 13 elements how do I do something to only elements 2,4,6,8,10 and 12? ...