loops

case-insensitive array_unique

I'm trying to write a few lines of code to make a case insensitive array unique type function. Here's what I have so far: foreach ($topics as $value) { $lvalue = strtolower($value); $uvalue = strtolower($value); if (in_array($value, $topics) == FALSE || in_array($lvalue, $topics) == FALSE || in_array($uvalue, $topics) == FA...

How do I do this without using a double loop?

I'm attempting to use the fields_for command to combine two models edit functions. I'm editing several variables. With these variables I'd like to include some basic information that is associated with the model, such as @line_item.inventory.item. The only way I could accomplish this is by creating a double loop which doesn't work for ob...

What's the difference between 'for' and 'foreach' in Perl ?

I see these used interchangeably. What's the difference? ...

Looping on an array in javascript?

i want to run a loop on a string type array, such that if array contains 1000 words than loop should give starting 200 values than break and when loop runs again than it should give values after previous 200 values, how it is possible in javascript? ...

WordPress Loop Destroys Post Reference

Doing something like this: <?php $my_query = new WP_Query('category_name=process&posts_per_page=20'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <li><a href="<?php the_permalink(); ?> "><?php the_title(); ?></a></li> <?php endwhile; ?> Destroys the original refe...

jQuery: Most efficient way to create blocks of HTML based on number of selected items?

So I have a basic HTML <select> element where a user can select a number. What I then need to do is create some list items in an unordered list based on the number they selected. What's the most efficient way to do that with jQuery? ...

How to iterate by row through a mysql query in php

Ok, So I am trying to query my database and select all rows that have a certain value. After that I turn the query into an array with mysql_fetch_array(), then I tried iterating by row through the fetched array using a for each loop. <?php $query = mysql_query("SELECT * FROM users WHERE pointsAvailable > 0 ORDER BY pointsAvailable Desc"...

Problem with a loop inside a PHP SQL statement

Here is my code, part of it is working flawlessly while the other isn't. <?php $query = "Select * from Query ORDER BY time DESC"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { ?> <span class="hotspot" onmouseover="tooltip.show('<center><b><?php echo $row['name'] ?></b></center>');" onmouseout="tooltip.hide...

Get a $date between start and end dates on a continuous loop

Trying to figure out a way of achieving the following scenario:- The user creates an initial time period e.g. 01/01/2013 to 01/07/2013 and a renewal period e.g. every 1 month. I'm working on a function that will:- Detect whether the date passed in a function (could be any date) falls a period matching the users requirements. For ex...

how to create a loop in a function with another function?

Thanks for the help guys ...

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto (in C)?

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto? Thanks, Chenz ...

Counter in Flash and Tweener as3

My scrolling counter is not displaying 1-9...only “zeros” every ten intervals. It plays, but the code is unfinished at line 37 in NumbersView.as. Notice Tweener is used to display the sprites. How do I finish this? WHAT I'M TESTING "NumbersView.as" loop error, onComplete, missing argument or function - Tweener code, line 37? - for loop,...

PHP - Getting position within a loop

Hi, I have a function which is called within a foreach loop and takes in two parameters, an integer, representing the number of times the loop has run and an array (of no fixed size). I would like to return the value of the array key that is equal to the counter. For example, if the array has four elements: A, B, C and D and the counte...

Distance Math in JavaScript and Implementing it in loop?

Hi! I'm having the difficulties with calculating distance between several points on the map: I have an array of coordinats where the first coord ["30.327547", "59.919676"] is the begining of the trip and other are pit stops: var J = [ ["30.327547", "59.919676"], ["29.84964", "58.737619"], ["28.250252", "57.785994"], ["3...

Javascript webkitTransform within a for loop

Hey, I've come across a strange problem whilst trying to mimic the native iPhone page transitions (slide current page out and new page in). Here's my current code (extracted from a larger file, with no errors when debugging, so code logic doesn't seem to be the problem): Notes: A new page is created when a link on the current page i...

how to get my while loop to work?

Hi, I have a programme in which I have written three functions, difference (that calculates the difference in numbers between arrays) sum (that totals the array up) and calculate difference which uses the difference function to determine what the next array should be). All these functions are working but I'm having problems getting the...

Assembly - Trying to reverse string, but it adds an extra character on the final string.

Hi folks. I'm rather new to Assembly (And programming in general, to be honest). I'm trying to play with the stack. The purpose of this code: Take in a String, limited to 80 characters Reprint the String as entered Print each character as it is pushed to the stack Print each character as it is popped from the stack Print the reversed S...

JavaScript: Can I add decimals?

for( count = 0.01; count <= 0.20; count + 0.01 ) Is this valid? Because it seems as soon as I changed it to this from count++, my firefox crashed. ...

Integer comparison in python slows everything down to a crawl

The following code is causing me enormous headaches: def extract_by_letters(letters, dictionary): for word in dictionary: for letter in letters: if word.count(letter) != letters.count(letter): if word in dictionary: #I cant leave this line out dictionary.remove(word) return d...

C# - How to create a non-detectable infinite loop?

This is just an "I am Curious" question. In C#-in-depth Jon Skeet says about lambda expressions: "if there is a nonvoid return type every code path has to return a compatible value." (Page 233) The footnote then says: "Code paths throwing exceptions don't need to return a value, of course, and neither do detectable infinite loops." (Pa...