loops

Java object creation

Im writing a program that creates an array of classes that run separately. I want to create an array of 500 containing a big class. Whenever i write the loop to create it, it stops at about 30 or so... is there a limit on java or bugging in my program? ...

maintaining a count in foreach

$count=0; $numb=50; foreach ($sepkeys as $dbkey) { for ($page=10;$page<=$numb;$page=$page + 10) { // the if block $count=$count+1; } } I am trying to maintain a separate a count for each key number in the above code. Eg: key- 574, it searches from pages 10-50 and increments the count. The problem that I have is the cou...

Invalidating loop bounds

I've recently inherited a project primarily done in C++, so this is my first real exposure to it. I'm wondering if I may have a problem erasing a vector's elements from within a loop bounded by the vector's begin() and end(). Here's (essentially) what I've been trying to do: for (vector<double>::iterator i = distance.begin(); i < dista...

Infinity Loop and user input as the termination

I have my code and it does go run to infinity. What I want is that if on the unix command window if the user inputs a ctrl C, I want the program to finish the current loop it in and then come out of the loop. So I want it to break, but I want it to finish the current loop. Is using ctrl C ok? Should I look to a different input? ...

Creating a program loop for the first time in objective-c

I am trying to add some "replay-value" if you will to my temperature scale conversion console program in Objective-C by adding a simple loop. Now, here is the code for my current main.m file: #import <Cocoa/Cocoa.h> #import "class.h" int main(int argc, char *argv[]) { int result; int prompt, prompt2, sourceTempText; double sourceTe...

JavaScript looping through an object while adding items

I have the following code segment: var run = 0; var obj = {'item1':0,'item2':5,'item3':10}; for (var i in obj){ run++ obj['newItem'+run] = 5; } return run; and it returns 3. But I want it to go on infinitely and eventually crash the browser. Is there any way of updating the obj variable while in a for loop? ...

Adding a second loop to a Wordpress theme on a separate page

I'm trying to add two loops to a theme on two separate pages: home and blog. Blog is basically an index of the posts. It's what most Wordpress pages default to as a home page. To accomplish this I went to "reading settings" and set "front page displays" as 'static' with "front page" set to a Home page I set up in Wordpress pages and "p...

loop through list of dictionaries

hello! i have a list of dictionaries. there are several points inside the list, some are multiple. When there is a multiple entry i want to calculate the average of the x and the y of this point. My problem is, that i don't know how to loop through the list of dictionaries to compare the ids of the points! when i use something like tha...

HtmlTextBoxFor Loop in MVC 2 C#

I am trying to do something that I think is relatively simple but can't get it to work and would be greatful for some pointers. I've got a form with a list of text boxes in it... Lets say, I want to find out "Your Favourite Pirates", and get you to list all ten on the page with comments as to why they are your favourite. So in my view...

standard for "loops" in XML?

Hi, I am designing a simple XML file for animations. I often get in the situation, that I write something like this: <frame> <image>./image1.png<image/> </frame> <frame> <image>./image2.png<image/> </frame> <frame> <image>./image3.png<image/> </frame> ... Now, this of course can get annoying. So I would I thought was allo...

What is better way to loop over two ranges - multiply them together and do it one loop, or loop over each range separately?

I can't decide how I should loop over ranges. This way: for (int i = 0; i < max_i; i++) { for (int j = 0; j < max_j; j++) { // first way - two loops } } Or this way: for (int k = 0; k < max_i*max_j; k++) { // second way - one loop } Thanks, Boda Cydo. ...

Populate dropdown menu based on groupnumber and MySQL answer

Hello! I am building an webapplication for retailers to register purchased products in PHP/MySQL. What I like to do now is to populate a dropdown menu in a form with the products the specific retailer sells. The retailer is assigned a value for each product that they are selling, and then the values are summed up and putten into the data...

Nested for loop inside a while loop - Java

Hello all, I was working on a Java web application, and had the following requirement with respect to looping in my HTML table. I've a nested for loop inside a while loop(both execute the same # of times, for ex. say 3). My code looks something like this: <table> <thead>...</thead> <tbody> if (patcases != null && patcases.size()...

How to produce several forms for a nested form ?

Intro I have an object @organization that has_many :quick_facts Basically, I want to produce a _form for each :quick_fact but with one save button, that saves all of the quick_facts. My two problems: First Problem: My quick_facts are not prepopulated with their information. They only appear as blank for each quick_fact I have. Se...

raw_input and timeout

I have thise huge code that I'm going to implement . Before I start that, I want to do a raw_input('Enter something: .'). I want it to sleep for 3 secs and if there's no input, then cancel the raw-input prompt and run the rest of the code. Then the code loops and implements the raw_input again. I want it so that if somedoes put a raw_i...

Python - Sum of numbers

I am trying to sum all the numbers up to a range, with all the numbers up to the same range. I am using python: limit = 10 sums = [] for x in range(1,limit+1): for y in range(1,limit+1): sums.append(x+y) This works just fine, however, because of the nested loops, if the limit is too big it will take a lot of time to compu...

PHP strpos() returning odd results

Hi folks, I've written a basic 'security checker' for my webapp. I'll need to see at a glance whether user-submitted code contains evil stuff. Here is a screenshot of the code that I'm running this against right now: http://cl.ly/677a6dc40034f096697f Here is the PHP code I'm using against these three bits of code: <!-- The View --> ...

if loop: x not in VS not x in

This is a strange question but here goes: I've noticed that both of these work the same: if x not in list and if not x in list. Is there some sort of difference between the two in certain cases? Is there a reason for having both, or is it just because it's more natural for some people to write one or the other. Which one am I more ...

Javascript "..." waiting dot looping with interval

Instead of using an animated gif, I would like to instead have text in a span: Waiting Waiting. Waiting.. Waiting... I would like to loop through each and then return to the first in an infinite loop. I would also like to control the interval to speed up or slow it down. I'd like to have my HTML to be: <p>Waiting<span id="dots"></...

infinite loop in functional programming ?

I was wondering: can infinite loops be done in functional programming? example: when using the windows API to get windows messages, it is usually implemented in a loop. I know it is possible to make a function that will keep going into recursion indefinitely. I expect that this will result in a stack overflow. are infinite loop the...