for-loop

JavaScript - Are loops really faster in reverse...?

I've heard this quite a few times. Are JavaScript loops really faster when counting backward? If so, why? I've seen a few test suite examples showing that reversed loops are quicker, but I cant find any explanation as to why! I'm assuming it's because the loop no longer has to evaluate a property each time it checks to see if it's finis...

Why is my for loop stopping after one iteration?

Racking my brains on this one. I have the code below: the first stages of a JavaScript game. All the objects are well-defined and I'm using jQuery for DOM interaction. The puzzle is created with the following JS code: var mypuzzle = new puzzle("{solution:'5+6+89',equations:[['5+3=8',23,23],['5+1=6',150,23],['5+3=6',230,23]]}"); Howev...

Replacing jquery each with for

I apologize in advance if this is a stupid question that betrays my lack of understanding of javascript/programming. I've been using $.each to do iterations for a while now, but I keep on hearing people say to use native JS for to do loops. I'm very concerned about performance but I am not sure if it's always possible to replace $.each...

Max number of transactions in MSMQ

We are planning to use MSMQ transaction in one of our application. I am not sure what is the maximum number of transaction we can have for MSMQ? ...

Any reason to replace while(condition) with for(;condition;) in C++?

Looks like while( condition ) { //do stuff } is completely equivalent to for( ; condition; ) { //do stuff } Is there any reason to use the latter instead of the former? ...

Which is more expensive? For loop or database call?

In general, which is more expensive? A double-nested for loop and one call to a database or a call to a database for each of N items in only one for loop? Not looking for an answer down to microseconds, just a general idea of which direction I should take. TIA. ...

PHP: Is it possible to use for loop inside a switch?

I'm attempting something like the following: switch ($p) { foreach ($modules as $m) { case '"'.$mod.'"': include 'modules/'.$m.'/cases.php'; break; } } but can't get it to work. Is it possible to use a for loop in this manner, inside a switch? ...

no pg_hba.conf entry for host

Hi All I am new to Perl as well as Postgresql I get following error when i try to connect using DBI DBI connect('database=chaosLRdb;host=192.168.0.1;port=5433','postgres',...) failed: FATAL: no pg_hba.conf entry for host "192.168.0.1", user "postgres", database "chaosLRdb", SSL off Here is my pg_hba.conf file: # "local" is for Unix...

Stops at for loop

When I am running my code, it always stops at the for loop and skips it. public void assignCell() { Prisoner prisoner = prisoners.get(id-1); for(Cell cell : cells) if(cell.isAvailable()) { cell.allocate(prisoner); String bunk = null; if(cell.isEven()) { bunk = "top bunk of cell...

For loop construction and code complexity

My group is having some discussion and strong feelings about for loop construction. I have favored loops like: size_t x; for (x = 0; x < LIMIT; ++x) { if (something) { break; } ... } // If we found what we're looking for, process it. if (x < LIMIT) { ... } But others seem to prefe...

How to count with 0

I want to count with 0. I means if $x = 002 $y = 999 Now I want to count it by keep the 00. for ( $i = $x ; $i <= $y; $i++ ) { echo $i; } but it echo - 002, 3, 4, 5 I want it to count by keep the 00. as like 005, 006, 007, 008, 009, 010, 011, 012. Please help me. I need it. Thanks ...

Making a for X in Y loop return whatever is returned by the statements it contains

Hi all, The following statement... content_tag(:li, concept.title) ...returns something like: <li>"My big idea"</li> The following method definition, when called, returns the same: def list_of_concepts(part) content_tag(:li, concept.title) end As does... def list_of_concepts(part) content_tag(:li, part.concepts.first.title) ...

Looping and file_get_contents in PHP

Hello, I have written a page that will scan a site and then extract certain code from the source. That part is working successfully, however I want to run this over multiple pages and dump the details into a database. I am stuggling to get the loop working, this is what I currently have (please be gentle this is my first attempt at anyt...

Why does my Perl for loop exit early?

I am trying to get a perl loop to work that is working from an array that contains 6 elements. I want the loop to pull out two elements from the array, perform certain functions, and then loop back and pull out the next two elements from the array until the array runs out of elements. Problem is that the loop only pulls out the first two...

How to write the dynamic source for image control in style for a button (APP.XAML) in silverlight 3?

How to write the dynamic source for image control in style for a button (APP.XAML) in silverlight 3? ...

Trouble with local variables in C#

I have a couple of variables that need to be assigned inside a for loop. Apparently, when the loop exits, C# ignores whatever happened in there, and the variables are returned to their original status. Specifically, I need them to be the last and next-to-last elements of a List. Here's the code: int temp1, temp2; for (int i = 0; i < toR...

For Loop do action every 5 results

can someone tell me the logic (in any language ) including pseudo code. on how to create a for loop an have it fire an action every 5 results it spits out. basically I'm just trying to emulate a table with 5 columns. Thanks! ...

Help me replace a for loop with an "apply" function

...if that is possible My task is to find the longest streak of continuous days a user participated in a game. Instead of writing an sql function, I chose to use the R's rle function, to get the longest streaks and then update my db table with the results. The (attached) dataframe is something like this: day user_id 2008/11/...

SASS - define variable in for loop

I was hoping that defining variables in a loop would work in SASS but unfortunately I get errors saying that the variable isn't defined, here is what I tried @for !i from 1 through 9 !foo = #000 @if !i == 1 !bg_color = #009832 @if !i == 2 !bg_color = #195889 ... #bar#{!i} color: #{!foo} ...

Example of a While Loop that can't be a For Loop

I know a while loop can do anything a for loop can, but can a for loop do anything a while loop can? Please provide an example. ...