loops

How to write a function to output unconstant loop

Here is the function description test($argv) $argv is an array, for example $argv=array($from1,$to1,$from2,$to2.....); array items must be even. $argv=array(1,3,4,5) : this will output values like below: 1_4 1_5 2_4 2_5 3_4 3_5 pseudocode is like while($from1<=$to1){ while($from2<=$to2){ echo $from1."_".$from2."<br/>"...

TypeError: coercing to Unicode: need string or buffer, User found

hi, i have to crawl last.fm for users (university exercise). I'm new to python and get following error: Traceback (most recent call last): File "crawler.py", line 23, in <module> for f in user_.get_friends(limit='200'): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pylast.py", li...

python: sorting

hi im doing a loop so i could get dict of data, but since its a dict it's sorting alphabetical and not as i push it trought the loop ... is it possible to somehow turn off alphabetical sorting? here is how do i do that data = {} for item in container: data[item] = {} ... for key, val in item_container.iteritems(): ... d...

I made a horrible loop.... help fix my logic please

I know I'm doing this a bad way... but I'm having trouble seeing any alternatives. I have an array of products that I need to select 4 of randomly. $rawUpsellList is an array of all of the possible upsells based off of the items in their cart. Each value is a product object. I know this is horribly ugly code but I don't see an altern...

as3 loops and event listeners

I have an array that returns multidimensional data from an mysql database, when this is collected the createNews function creates the user interface. The problem I am having is the loop is iterating quicker than the UI is being created, is there a way to use event listeners with loops so it only continues after my function has completed ...

Ruby: Is it possible to have a for loop that increases more than one at a time?

For example: for(int i = 0; i < 100; i += 2) I could use a while loop or check if i % 2 == 0, but I was wondering if there wasn't a way to do it with the for loop. I could also use for(int i = 0; i < 50; i++) and multiply i by 2, but that doesn't seem right either. I'm just wondering if there is a simple, straightforward way to do it. ...

Text Hints with JQuery and JavaScript for loop

Hey guys! I'm developing a small app where i ask users to put some info. I want to show text hints in the input fields. I do this in a for loop... When the page is loaded, the hints are displayed correctly but nothing happens on 'focus' and 'blur' events... I'm wondering why since when I don't use a 'for loop' in my js code, everything...

How to Loop & rename MySQL table in Perl

Hi, Could you plesae teach me how to Loop & rename MySQL table in Perl. Thanks. my code snippet attached use strict; use warnings; use DBI; my $dbh = DBI->connect( 'DBI:mysql:database=dbdev;host=localhost', 'dbdev', 'dbdevpw', { RaiseError => 1, AutoCommit => 1 }, ); my $sql = RENAME TABLE old_table TO new_ta...

Deleting duplicates in Delphi listview

I am trying to remove duplicates in my listview. This function: procedure RemoveDuplicates(const LV:TbsSkinListView); var i,j: Integer; begin LV.Items.BeginUpdate; LV.SortType := stText; try for i := 0 to LV.Items.Count-1 do begin for j:=i+1 to LV.Items.Count-1 do begin if SameText(LV.I...

Is recursion ever faster than looping?

I know that recursion is sometimes a lot cleaner than looping, and I'm not asking anything about when I should use recursion over iteration, I know there are lots of questions about that already. What I'm asking is, is recursion ever faster than a loop? To me it seems like, you would always be able to refine a loop and get it to perform...

When I assign ringtone in android using code it won't paly it in a loop, why?

I use this code: ContentValues values = new ContentValues(); values.put(ContactsContract.Data.CUSTOM_RINGTONE, Environment.getExternalStorageDirectory().getPath() + "/ring.wav"); getContentResolver().update(ContactsContract.Contacts.CONTENT_URI, values , "DISPLAY_NAME = 'Ani'", null); It works great but it play only one time. How do I...

Idiomatic Python: 'times' loop

Say I have a function foo that I want to call n times. In Ruby, I would write: n.times { foo } In Python, I could write: for _ in xrange(n): foo() But that seems like a hacky way of doing things. My question: Is there an idiomatic way of doing this in Python? ...

How can I speed-up this loop (in C)?

Hi! I'm trying to parallelize a convolution function in C. Here's the original function which convolves two arrays of 64-bit floats: void convolve(const Float64 *in1, UInt32 in1Len, const Float64 *in2, UInt32 in2Len, Float64 *results) { UInt32 i, j; for (i = 0; i < in1Len;...

Using a Loop to add objects to a list(python)

Hey guys so im trying to use a while loop to add objects to a list. Heres bascially what i want to do: (ill paste actually go after) class x: blah blah choice = raw_input(pick what you want to do) while(choice!=0): if(choice==1): Enter in info for the class: append object to list (A) if(choice==2):...

Create variable names using a loop in Java?

Hi, first time poster, long time reader so be gentle with me :) See the following code which works to generate me timestamps for the beginning and end of every month in a financial year. int year = 2010; // Financial year runs from Sept-Aug so earlyMonths are those where year = FY-1 and lateMonths are those where year = FY int[] earlyM...

Why does this break statement break not work?

I have the following code: public void post(String message) { final String mess = message; (new Thread() { public void run() { while (true) { try { if (status.equals("serviceResolved")) { output.println(mess); Game.log.fine("T...

Using fopen and str_replace to auto fill a select option

Hi Everyone, I have this file 'gardens.php', which pulls data from a table called 'generalinfo' and I use fopen to send that data to a file called 'index.html'. Here is the issue, only one option is filled. I have a demo running here Garden Demo <-- this is a new updated page and location, there are more errors than I have locally If an...

Looping through multidimensional array starting from second array in PHP, if exists

I am returning an SQL query from database using PEAR into an array. $db_results = $db->getAll("SELECT * FROM loans ORDER BY amount, length, true_interest_cost"); If the query return results, I would like to show the first result formatted in one way and then the rest of the results formatted another way. So, my end result would look ...

Looping through Markers with Google Maps API v3 Problem

I'm not sure why this isn't working. I don't have any errors, but what happens is, no matter what marker I click on, it always clicks the last marker. Im not sure why though because the_marker is set up the same way. How can I fix this?: (Updated with new jQuery + XML) $(function(){ var latlng = new google.maps.LatLng(45.522015,-12...

How to make a try-catch block that iterates through all objects of a list and keeps on calling a method on each of them until there are no more exceptions to catch?

Basically iterating through a list and, - Invoke method on first object - Catch first exception (if any); if there are no more exceptions to catch, return normally. Otherwise, keep on invoking method until all exceptions are caught. - Move on to next object. I can iterate through each object, invoke the method, and catch one exception b...