Loops are a type of control flow structure in programming in which a series of statements may be executed repeatedly until some condition is met.

learn more… | top users | synonyms

0
votes
0answers
11 views

Suggestions for data extraction Data in fortran [migrated]

I use F95/90 and IBM compiler. I am trying to extract the numerical values from block and write in a file. I am facing a strange error in the output which I cannot understand. Every time I execute the ...
0
votes
1answer
15 views

Range of all variables in List in Prolog

I have a list in Prolog like this: Puzzle = [ A1, A2, A3, B1, B2, B3, C1, C2, C3 ]. And I want every variable in the list to be a number in the range of 1 to 9. Currently ...
1
vote
1answer
63 views

High School Java Class: Pong Project External Reviewer

Panelball class: import java.awt.*; import java.awt.event.KeyEvent; import javax.swing.*; public class Panelball extends JPanel implements Runnable { private static final long ...
1
vote
3answers
87 views

How to flatten the nested for loops?

The problem I am facing is: I need to interate through a bunch of lists, and there are separated conditions which needs to be satisfied by the list. conditons are not independent. I care about the ...
2
votes
1answer
82 views

Iterate through a LinkedList in a cleaner manner

I have a collection of PlaylistItem objects. They are linked together such that each item knows the ID of its next/previous item. I am iterating over this collection of objects, starting at a known ...
0
votes
1answer
60 views

Improvment of and looping in a regular expression pattern

My implemented regex pattern contains two repeating symbols: \d{2}\. and <p>(.*)</p>. I want to get rid of this repetition and asked myself if there is a way to loop in Python's regular ...
2
votes
1answer
107 views

Optimization expression evaluation chalange

It's my first message on this site. I'm trying to evaluate/learn C#. I'm an old (C++, MFC) programmer. I'm trying to learn C# with this little program(game) for my children. I'm trying to calculate ...
1
vote
1answer
36 views

Return most common items in list (php)

I was wondering what's the best way to return the most common items in a list, so far the best way I could do it was: //@param string $this->matched_ids_list = 1,11,12,11,12, ...
3
votes
2answers
198 views

Does this simple C++ program need any further improvement?

First of all I'm a complete noob when it comes to programming. So please forgive me if I unwillingly say something stupid. Now this is my first program written in C++ that I chose to make public in ...
1
vote
0answers
77 views

new md5 algorithm

can you please try my algorithm and give a comment or feedback about it? thank you in advance.. :) this is in java language just copy and paste all of it and run in e.g. netbeans or eclipse thanks ...
5
votes
4answers
159 views

Improve VBA code Excel

Im looking for someone who can improve my code, because at the moment it takes 4 minutes to execute. I'm new to VBA so it's probably bad coding. Normally if you are good in VBA you will understand the ...
0
votes
1answer
52 views

Proper use of reduce, nested loops

Below is an implementation of Dijkstra's shortest path algorithm. It's input graph is represented as an association list of source nodes to assoc of target node and arc weight. My question is about ...
4
votes
3answers
179 views

How to increase the performance of loop in Python?

I need to run over a log file with plenty of entries (25+GB) in Python to extract some log times. The snippet below works. On my test file, I'm ending up with roughly 9:30min (Python) and 4:30min ...
2
votes
1answer
50 views

Vectorize or otherwise speed up a double for loop

I have this function containing some loops and a double for loop. What it does is set up a matrix first to store results in (the task at hand is comparing genomes) and then with sliding window, ...
2
votes
4answers
108 views

Remove code duplication inside of a loop preserving performance

I'm coding a 2D collision engine, and I need to merge adjacent axis-aligned bounding boxes depending on a direction (left, right, top, bottom). The four cases are very similar, except for the if ...
4
votes
1answer
51 views

Looping through Radgrid in JS is slow, can this be faster?

I do a single select in one radgrid, and based upon that selection I want to select multiple rows in a different radgrid: <telerik:RadGrid ID="rgPaymentLines"> <ClientEvents ...
1
vote
1answer
54 views

Too many variables?

This is my first C++ program and I was wondering if I'm using too many variables. Its a simple program that gets a number from a user and calculates the number of primes between 3 and the user's ...
1
vote
2answers
53 views

Setting a OnClickListener in a loop

I am trying to set a OnClickListener to a image in a loop. If the params platform is "android" then use market app, instead of default browswer. Is there a better solution to my exception handling or ...
3
votes
1answer
44 views

Code to find the proper index comparing 3 values for max one

I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value. I.e. if array[i + 1][j + 1] has the largest value among the 3 ...
1
vote
1answer
113 views

PHP - is my code efficient?

I am basically getting data from various APIs and using PHP to put them together - like a web mashup. I am currently using 4 foreeach statements to insert the gathered data into their individual ...
4
votes
5answers
209 views

Want to remove the goto in my code

I want to remove my goto's in this code but I'm not sure how. There must be a cleaner way to write my code. Perhaps move the "if" statement to the end of each loop then use break? Sorry if this is a ...
1
vote
2answers
60 views

A program that mimics T9 cell messaging

Today I solved a question from Google Code Jam. A program that mimics a cell phone keypad messaging. Here is the program, with goto statement, I know it is unstructured style to use goto, but I still ...
0
votes
1answer
56 views

I have 2 errors about syntax that i can't find. it's in if else loop [closed]

I have 2 errors in the if else loop and i don't konow what? Thanks for help me. I am a beginnner. #include <cs50.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> ...
1
vote
1answer
56 views

Django how to make this view faster?

I have view and it works correct, but very slow class Reading(models.Model): meter = models.ForeignKey(Meter, verbose_name=_('meter')) reading = models.FloatField(verbose_name=_('reading')) ...
1
vote
1answer
105 views

Is there a better way to loop through records and call an api?

I have a CakePHP function here that gets info for a twitter screen_name from the twitter api and writes it to a mysql db. I'm just looking for feedback about other ways to accomplish this that might ...
3
votes
2answers
173 views

Removing the massive amount of for-loops in this code

Are there ways to avoid this triply nested for-loop? def add_random_fields(): from numpy.random import rand server = couchdb.Server() databases = [database for database in server if not ...
2
votes
0answers
82 views

Speed up a monte carlo simulation with nested loop

I would like to know if there is a more efficiency way to speed up below code. It uses a procedure where subsampling is required in the nested loop (which a previous answer ...
1
vote
1answer
70 views

File loop and logic in controller of view header?

I have the following in the header.php file which is included in all of my views: $dh = opendir(Vs.get_class($this).'/js') ; while($script = readdir($dh)) { if(!is_dir($script)) { ...
1
vote
2answers
153 views

How to Format Clean Accumulation Code?

I often find myself writing methods in languages such as Java or C++ that are only meant to loop over an array or something similar, accumulate the values, and then return the total. The problem is, ...
4
votes
1answer
194 views

efficient looping procedure to find the longest common substring java

I retrieved 200 tweets using jersey API. I want to find two tweets which have the longest common substring. This is what I have got. tweetList is an ArrayList of Tweet Objects. comapreTweets method ...
2
votes
4answers
122 views

Retrieving lists of consecutive capitalised words from a list

Ok, so given the string: s = "Born in Honolulu Hawaii Obama is a graduate of Columbia University and Harvard Law School" I want to retrieve: [ ["Born"], ["Honolulu", "Hawaii", "Obama"], ...
12
votes
4answers
779 views

Improvement on these horrible nested for loops?

This does the job, but is not especially elegant. What is the preferred Pythonic idiom to my childish nests? def bytexor(a, b): res = "" for x, y in zip(a, b): if (x == "1" and y == ...
2
votes
1answer
96 views

Rewriting nested for loops to give better formatted output

The following is code from a university practical I am doing. It reads in a txt file of twenty clients, whose information is stored in the txt file like this: Sophia Candappa F 23 00011 As ...
4
votes
3answers
231 views

How to improve this method? (Create text without repetition)

The basic idea is not to allow the same texts and add +1 at the end. Imagine that I have a datagrid (wpf) with names, and every time I click the add button, I will put a new name on the list ...
1
vote
1answer
116 views

C arrays and loops optimization

I am writing a program for learning purposes that takes an input of a file structured similarly to: 13,22,13,14,31,22, 3, 1,12,10 11, 4,23, 7, 5, 1, 9,33,11,10 40,19,17,23, 2,43,35,21, 4,34 ...
3
votes
2answers
117 views

Is this a right and effcient way of checking AND in a for loop

Just saw this at work in a code review and was wondering if this style of coding - for loop, doing && like that, seems fine to you or is there a better way of doing the same? for (int j = 1; ...
5
votes
4answers
255 views

Improve speed for looping through 1,000's of items in javascript?

This is a script I use to count how many items are selected in a form. Currently it loops through the entire form to count how many check boxes are selected, each time a checkbox is clicked. The form ...
5
votes
5answers
403 views

Looping over a list, checking a boolean and return value

public boolean checkNameStartsWith(List<Foo> foos) { for (Foo foo : foos) { if (!(foo.getName().startsWith("bar"))) { return Boolean.FALSE; } } return ...
2
votes
3answers
94 views

Trying to Find a Loop to use for a specific MySQL query

I'm trying to see if there is a loop I can use in order to pull off this code a little more elegantly. I was previously using a foreach($row as $cell) with $row = mysqli_fetch_row($result) but because ...
4
votes
1answer
135 views

Optimizing Python / Numpy Code

So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy. I've written a pure numpy version of the actual mean shifting per pixel (which I ...
1
vote
2answers
63 views

Request for help to tidy up code involving arrays and loops

I posted the following code on here a few days ago: public class Practical4_Assessed { public static void main(String[] args) { Random numberGenerator = new Random(); int[] ...
2
votes
1answer
247 views

filter a collection in a PagedCollectionView

I have scenario wherein I have to filter a collection in a PagedCollectionView. The filter criteria are Name and status which are check boxes with Enabled and Disabled labels If Enabled is checked it ...
4
votes
2answers
153 views

Understanding the use of for loops as counting loops in homework review [closed]

Newbie here, first time programmer. I have a homework assignment that I am working on. Instructions: Write an application that allows input of an integer n between 1 and 71, and (using a for or ...
2
votes
1answer
48 views

how to get B+ matrix (warshall algorithm) in matlab?

Pseudocode: // B = nxn binary matrix // Bm = resulting matrix for (i=1; i<=n; i++) { for (j=1; j<=n; j++) { if (B[i,j] == 1) { for (k=1; k<=n; k++) { Bm[i,j] ...
5
votes
1answer
123 views

How to speed up this following code

I am doing my research about scheduling by using Matlab. I am a new Matlab user and I have a problem with time execution of my following code: clc clear all A=8; B=12; C=10; ProcessTime= [ 11 11 11 ...
4
votes
1answer
967 views

Java 2d array nested loops

Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both ...
1
vote
1answer
88 views

Efficiency of grid generated by for-in loop

I've spend the last several hours working on a loop designed to take items in an array and arrange them as a so to speak "gird" of UIButtons. As far as I've been able to see through testing this code ...
5
votes
2answers
160 views

How to improve this Python code (complicated looping)

Basically, I have a list, newtry of blocks and I want to find a value of catchtype that makes them all return true for block.isCatchExtendable(newhandler, catchtype) or report an error if this can't ...
0
votes
1answer
62 views

what is wrong with the loops [closed]

I am solving a problem of adding the last digits of numbers lying between a range (for ex. between 'm' and 'n' where m < n).I have coded this #include <stdio.h> int main() { int t=0; ...
3
votes
1answer
139 views

return false if one of members fails a condition

I want to validate a list of objects for example strings. and if one of the objects fails to pass the condition return false as validation result . this is the code I use : public static bool ...

1 2 3