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

2
votes
1answer
42 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. ...
-1
votes
0answers
15 views

Reading a file and looping through until a match found [on hold]

I have been trying this code to loop through randomly until a match found in the lookin.txt file and stop with no success as my Python knowledge not that brilliant. I wonder if someone can direct me ...
1
vote
1answer
52 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
83 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
14 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. ...
0
votes
3answers
62 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
52 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
56 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
29 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
189 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
58 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
228 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 ...
2
votes
1answer
41 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
128 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
45 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
55 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
28 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
244 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
60 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
272 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
213 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
55 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
63 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
60 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
48 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
41 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
76 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
31 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
80 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
88 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
53 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
77 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 ...
4
votes
0answers
45 views

Simplifying the building of an adjacency array starting from a flat structure

Purpose: to make an adjacency PHP array with parent_id, name, level and ...
6
votes
3answers
199 views

Panagram Solution - Best approach?

I want to check if the given string is a Panagram or not. A Panagram is a sentence containing every letter of the alphabet at least once. This is what I've come up with as solution: ...
0
votes
0answers
60 views

Speed up Pandas DataFrame expansion to include time-lagged information about events

Using pandas and Python 3, information about a simple timeseries data set is being processed. Within the span of .5 seconds, 3 names are being said. We record the onset of each utterance, the length ...
5
votes
2answers
231 views

Applying different filters within loops

What I have is an outer loop which loops through a list of strings, followed by another loop which loops through a list of filters; and if the current column is the current filter in the list of ...
6
votes
2answers
204 views

Array from file

I have this code which is performed each time I click the 'show polygons' button. The problem is that it takes a few seconds to finish running through the code before actually drawing the polygons + ...
5
votes
1answer
116 views

Using Reddit API in R

I'm scraping some comments from Reddit using Reddit JSON API and R. Since the data does not have a flat structure, extracting it is a little tricky, but I've found a way. To give you a flavour of ...
4
votes
3answers
434 views

More efficient loops to generate unpronounceable words

I wanted to write a function to generate only unpronounceable words. I realised afterwards that the same thing could probably be achieved by just taking out the vowels. Regardless, I feel that there ...
2
votes
2answers
68 views

Optimizing a particle filter weighted selection step

I have a vector with 10000 particles that I use in a Particle Filter. The problem is that it's taking too long to compute the weighted selection of the particles. I want to use a vector of weights ...
5
votes
1answer
99 views

Pausing a SwingWorker with a Timer

I made a SwingWorker which is fetching tweets using the twitter4j API. The twitter API will allow 180 queries every 15 minutes, and then throw an exception with ...
4
votes
3answers
233 views

More efficient and readable nested loop to compare keywords

I've created an algorithm which weighs the relevance of a list of articles against two lists of keywords that correlate to attributes of the article. It works great and is super efficient... but it's ...
3
votes
1answer
80 views

Where is the bottleneck in my Cython code?

The profile tells me it took ~15s to run, but without telling me more. ...
7
votes
1answer
132 views

Incrementing letter-spacing of one line of text

I was asked to create a script which will increment the letter-spacing of one line of text, until its width matches that of the first line; for use in headline/subheadline text to maintain a block ...
6
votes
1answer
275 views

Sorting numbers into bins

I have two 2D arrays of doubles a and b. Both have two rows and different numbers of columns. ...
4
votes
2answers
83 views

Finding matching strings in a column

I have col D (in sheet1 called Students), col A (in Sheet2 called Students too) and col B ...
3
votes
1answer
45 views

Showing the domain of a URL

I have such a method which takes a URL, such as http://twitter.com/ttt or twitter.com/dasd, and should show its domain with http: http://twitter.com and name twitter ...