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

learn more… | top users | synonyms

3
votes
1answer
22 views

Finding candidate with the most matching values

I haven't coded all winter, and it seems like everything I learned about efficiency from my data structures class leaked out my head. I was wondering if I can get some help in making my code less ...
-1
votes
0answers
18 views

Looping through array and aggregating result in PHP [on hold]

I need to loop through a set of data (example below) and generate an aggregate. Original data format is CSV (but could be other kind). Data is ordered by LOGON and QUERY ascending. ...
6
votes
1answer
95 views

An algorithm that finds the number of “lined up columns”

I found this question in an old exam in computer science. I solved it in a good way, but I'm not convinced that my solution is the best solution. I believe that there's a better way to solve it. ...
-1
votes
0answers
8 views

Cursor relooping problem SQL [on hold]

I have a cursor, that keeps relooping creating more and more documents. There are only one document record in the database. Can anyone see where I am going wrong here? ...
2
votes
1answer
59 views

Producing a pyramid of capital letters

Now I'm reading C Premier Plus by Stephen Prata and there's an exercise 4 in chapter 6 which has no solution in the book, so I can't check if I did it properly. My code works like it should, but I ...
6
votes
1answer
115 views

Cash Register Challenge

Challenge: Design a cash register program Specifications: Your register currently has the following bills/coins within it: 'PENNY': .01, 'NICKEL': .05, 'DIME': .10, 'QUARTER': .25, ...
2
votes
1answer
33 views

Efficient Traversal and Manipulation of the DOM with Native JavaScript Using For/In Loop

With native JavaScript, I intend to traverse a collection of elements in the DOM that contain a link and an image (and possibly other elements). The image may or may not be inside the link—in ...
7
votes
2answers
112 views

Mastermind code taking hours to calculate

I'm trying to implement Knuth's Five-guess Mastermind algorithm in my own version of Mastermind, but when running step 6 it takes my code hours to actually run through everything to get the neccesary ...
4
votes
2answers
64 views

Java calculator for long calculations involving positive integers

I'm making a calculator that can solve calculations that are inputed in a very raw form. Say: "3*52+11+3/2" I'm using the console, at least for now. This will also take in consideration that ...
-4
votes
1answer
65 views

Is this a better loop? [closed]

My team has a lot of code written with fairly traditional for-loops: for(int i=0; i < Something.GetSize(); ++i) { /* do work */ } But recently, some devs ...
-2
votes
2answers
95 views

return inside a loop - is it a good style? [closed]

Is it a bad style to return inside a loop? I have the following method ...
7
votes
3answers
335 views

Project Euler #2 (Fibonacci Sequence)

Challenge: The Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. Consider a ...
1
vote
2answers
51 views

WordPress: multiple loops

I have two loops on my page - each with their own category. It works, but I don't know if this is the best practice as I'm pretty new to this stuff. ...
4
votes
4answers
546 views

Project Euler #5 (LCM of 1-20)

Challenge: 2520 is the smallest number divisible by 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by 1-20? Solution: ...
1
vote
1answer
62 views

Are nested foreach loops to compare two multidimensional arrays efficient in PHP?

I've got the following PHP code, which is taking a search term, and checking if any of the search terms could be or could have a nickname. ...
2
votes
3answers
357 views

Program that multiplies numbers over and over

Would appreciate a review on this. The program does work as it is intended to. However I am unsure if there is a more elegant or better way to execute this process with less code. ...
2
votes
1answer
67 views

Javascript Performance Optimization

I am using the code below that loops around thousands of time, I need this to be as fast as possible, however I am not an expert in Javascript and all I know is that this code is faster than doing it ...
5
votes
1answer
75 views

Basic 30 TPS server loop

I've created a console server which is supposed to update 30 times per second, I'd like you to review it and also I'm curious about the accuracy of the server's loop. ...
2
votes
1answer
75 views

Very slow graph walking

My code is very very slow. Could you give me hints on how I can make it much faster? ...
3
votes
3answers
92 views

LINQ foreach - error handling and general improvement

I'm looking for two kinds of feedback: Is there a better way of doing what I'm attempting to do? Any obvious weaknesses that could potentially cause problems? The code in question (I've broken it ...
0
votes
1answer
27 views

Convert Array CSV to Object using Header

Takes the first array in the array and uses that to set the properties of an array-object. ...
1
vote
3answers
76 views

Looping to update article codes on one server based on queries on another server

I've read somewhere on Stack Overflow that doing queries in a loop is very inefficient. It will hammer your SQL server and make your script very slow. Sample code: ...
6
votes
2answers
55 views

Modular arithmetic brute-force congruence finder

My full code is running too slow. I do profile.run to my project and found out this function consumes a lot of time. The main problem is just to return an array containing all \$x\$ satisfying both ...
3
votes
1answer
79 views

Morse Code Converter

I wanted an uncomplicated project to get myself started again. Although this works I was wondering if it's the best approach, especially when it comes to validation parts? It seems to me that I'm ...
2
votes
0answers
36 views

Speeding up loop-rich Matlab function to calculate temperature distribution

I would like to speed up this function as much as possible in Matlab. This is part of a bigger simulation project, and as it is one of the most called functions within the simulation, this is crucial. ...
6
votes
2answers
192 views

Longest string in a vector — two implementations

I was given this piece of code, which calculates the length of the longest string in a vector of ...
3
votes
2answers
64 views

Improving Matlab function within big simulation

I have a very big Matlab simulation project in my hands, which I wanted to optimize, since I'm running it many times to tune parameters and the like. Using Matlab's ...
5
votes
2answers
230 views

Improving a method to guarantee uniqueness

I have just written something to guarantee a unique URL when creating pages within an old legacy system (sounds odd doing this retrospectively but we've just changed how the routing works). I don't ...
3
votes
1answer
49 views

Dynamically adding and removing HTML classes

I am trying to add an active class to my subnavigation using the waypoints jQuery. I am trying to avoid writing multiple functions to adhere to the DRY idea. The waypoints toggle the function based on ...
2
votes
3answers
139 views

Loop termination check for multiple types of host reachability tests

I have 2 booleans: host.isReachableOnLan, and host.isReachableOnWan I have a listener ...
1
vote
3answers
51 views

AudioMetaTagger: recursively read files and gather metadata

So the idea is to read metadata recursively in a chosen directory, load their metadata and display it into a table. Here is the simplified example of what I am doing. ...
4
votes
2answers
57 views

Substituting Hebrew letter variants

I have two functions that replace letters. In one function, I'm replacing a regular Hebrew letter with its final form, and the other function undoes this operation. (Consider it like ...
3
votes
1answer
30 views

Merging predicted values into measured values

I created the following function below to merge the real values with the predicted values (when real are absent) in a new column in data.frame. The function ...
4
votes
2answers
265 views

Scaling jsTree performance

I am using jsTree v1.0 (latest v3.0, they withdraw support from older versions) to display the hierarchy in my application. It was good until until I started showing groups/user up to 200 levels, but ...
4
votes
1answer
85 views

Number-guessing game with maximum and minimum values

This is a simple guessing game where you are prompted for a minimum and maximum value, then you must guess the number the computer chooses! This is the first program I have written so any and all ...
5
votes
3answers
273 views

Avoiding label in a loop to sort links

How can I refactor my code to remove the label and the need for it? I am aware that a loop with label is "forbidden". But I can not find a way to rewrite this without the label. ...
4
votes
1answer
336 views

Using array values to create variables, if statements and highchart dataset

I am trying to make my script maintenance-free by replacing some "static" variables and labels with dynamic ones. The main function of my code is to extract data from a SharePoint-list which contains ...
4
votes
1answer
62 views

Efficiency of looping though a text map to draw objects

I am making a game that uses a text map to draw obstacles and courses for the player to navigate. However, I am concerned that my method of looping through the text map to draw objects on the screen ...
4
votes
1answer
65 views

Speeding up nested for-loop analysis code

I have two matrices, the first one is mat 2000*500, the second one is 6000*500 ...
3
votes
0answers
62 views

Another way to loop this code in AutoHotKey

I have a working AutoHotKey code, but I am curious if there is a better/shorter way to do this loop: ...
3
votes
1answer
49 views

Fast counting of interactions between groups given users interactions and groups assignments

Given: An array c that contains the group assignment of every user (c[i]=4 indicates that user i belongs to group 4) A matrix ...
3
votes
1answer
44 views

Loop through products and return first product that matches criteria

I am writing a function which loops through an array of products. The function needs to return: the ID of the first product that has an image and is ...
-3
votes
1answer
78 views

Count percentage of audio samples exceeding a threshold

I have this practice question that I have an answer to: In this stage of the project, you will identify any "danger" spots, in which the SPL is greater than or equal to 80 dB (the value above ...
2
votes
1answer
32 views

Simple for loop to calculate headers size based on a specific ratio

How can I improve the following for loop (wannabe function) to create harmonic sizes for headers based on a specific ratio? ...
10
votes
4answers
2k views

Possible antipattern: looping until a search condition is met

Whenever I write a loop, I always use closure if it's appropriate by way of a self-executing anonymous function. I will typically write my searching loops as follows: ...
6
votes
3answers
1k views

Generating a not-the-same-as-last-time random number

I have to generate random number which differs from the number generated last time. Which of these two variants is better? Or maybe you can suggest better implementation. ...
1
vote
2answers
84 views

Notifying Students in Courses - Strategically

I have the following implementation, and hope to get suggestions on how to improve the code. treeListViewModel.Courses is an observablecollection ...
5
votes
1answer
92 views

Vector comparison inside for-loop

The following code finds no-rain periods in a time series that were preceded by rain over a threshold (e.g. 10mm in 2 days [k=48]). ...
4
votes
2answers
54 views

Determining if a discount is valid for a product

I'm in the process of re-writing a method I've come across in our code base. It's pretty lengthy and a lot of it seemed redundant. It's a Discount object class ...
6
votes
1answer
81 views

MicroC task switching

My background for this review is a university course in embedded systems using MicroC and this question. Now my program appears to run ok, but I'd like to know what you think can be improved or if the ...