Tagged Questions

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

0
votes
0answers
23 views

newGame() loop doesnt work. Application exits without notifying [closed]

I got a couple issues with my code. I know it is not the best looking design/coding but I don't claim to be a good programmer. I want my game to ask to player if he/she wants to play again after the ...
0
votes
0answers
6 views

Getter within loop returning null after assigning values [migrated]

I've got a slight problem with my program. Simply put, what I do is this: Choose the option to "Add a new Student record". When I try to display the newly added values (First Name, Last Name, ...
3
votes
1answer
62 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
35 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
48 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
44 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
44 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
23 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 ...
-5
votes
1answer
49 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
30 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
969 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
78 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
84 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
51 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
69 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 ...
3
votes
0answers
30 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
177 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
39 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
203 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
199 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
91 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
393 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
61 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 ...
4
votes
1answer
76 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
218 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
66 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
116 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
271 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
76 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
42 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 ...
3
votes
2answers
78 views

While loop uses extra variables - can this be cleaned up?

A piece of my program allows the looping and incrementing of a targeted entity to be used in a while loop somewhere else. Here is a sample of the while loop: ...
5
votes
3answers
774 views

Assigning value to cells with Excel VBA

I have an Excel Worksheet consisting of two columns, one of which is filled with strings and the other of which is empty. I would like to use VBA to assign the value of the cells in the empty column ...
3
votes
1answer
119 views

Is this roulette selection extension method beautiful or disgusting?

So I just wrote the following extension method to do roulette selection on a generic list. I'm specifically unsure of the use of the while loop. Is this beautiful or a disgusting mess? ...
3
votes
6answers
240 views

Looping through an array of strings containing approximately 3 million elements

I have a function that loops through an array of strings containing approximately 3 million lines of strings. My problem is this loop is running too slowly and I want to know how to make it faster. ...
5
votes
1answer
62 views

Periodically checking for internet connection

I have a SwingWorker which checks periodically for an internet connection and updates a jLabel accordingly. ...
6
votes
2answers
89 views

Basic Imitation of C# Enumerable in VBA - or any other static class

Since implementing static classes in VBA actually seems possible I came up with an idea to try to imitate C#' Enumerable class (well, to some extent...). This is ...
1
vote
2answers
478 views

Printing the sums of numbers from 1 to 10 with only 1 loop

The code below prints sum from 1 to 10: 1 1+2 = 1+2+3 = 1+2+3+4 = ...... 1 + ... 10 = 55 ...
2
votes
3answers
542 views

Foreach loop to generate HTML table with title in first cell of each row in PHP

I've used quite a lot of foreach loops to achieve this type of HTML table that has titles in the first cell of each row: ...
7
votes
3answers
415 views

Ticket management system

I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows. For ...
5
votes
3answers
52 views

Faster way to group email-date pairs by date without many nested for loops?

Given list of pairs (email-date): ...
6
votes
2answers
258 views

Improving performance for Codility max slice swap problem

Problem Description: Find the maximum sum of a compact subsequence of array elements after performing a single swap operation. Solution: ...
3
votes
2answers
75 views

More efficient way to draw bufferedimage into another

For what I'm doing, I need to be able to draw a buffered image directly into a larger buffered image. I've searched around a little and still have failed to find a better way, but my current way is ...
3
votes
2answers
116 views

Multiple loops versus multiple stringbuilders

I've come across the following piece of code in a Razor view ...
7
votes
1answer
116 views

Perfect game loop

I've been working on development for an Android game, and this is the game loop I have so far: ...
5
votes
1answer
96 views

Efficiently matching IP addresses with a list of CIDRs

I am using Python3 to extract some information from a dictionary that contains 10k of CIDRs, but the running time is pretty long. Here is my purpose: I have a dictionary of CIDRs (10000) and a list ...
5
votes
1answer
75 views

ListBox Update Handling

I have UserGroups for Users to be assigned to in a ListBox in HTML form. Items from listbox can be multi-selected or completely ...
2
votes
2answers
94 views

List of search results using Selenium

I have written the following code for looping through WebElements in Selenium. Can someone please provide me with feedback on how to improve my code? ...
1
vote
2answers
58 views

Looking for matching names among two text files

I'm trying to enhance the execution speed of my below code. I am using only vanilla JavaScript. I would be willing to bring in additional libraries and plugins as long as they will enhance the overall ...