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
3answers
36 views

Displaying days of the week for all of 2015

This program is supposed to determine the day of the week for 2015. Could someone tell me how I could shorten my code? ...
-5
votes
0answers
25 views

Ten Green Bottles please give me a hand i cant work it out [on hold]

This open a file given as filename for reading returns the String containing the contents of the file ...
-1
votes
0answers
20 views

PDO object directly in while-loop instead of from a variable [closed]

I thought this should work: ...
3
votes
1answer
23 views

Updating an inventory with R using apply functions

I have created an inventory that works via QR codes. Briefly: the QR code codes for an email with the book/student checking it out. The email is downloaded into R using the gmailR package (code not ...
2
votes
3answers
65 views

Showing the path of a projectile

I'm trying to dive deeper into C#, and so I've been experimenting with some code. I'm creating a console application that shows the path of a projectile depending on the angle, and it works great! You ...
2
votes
0answers
13 views

Optimizing D3 Stream Graph Code

I have two javascript functions that generate a D3 Stream graph. I feel I may be excessively and unnecessarily iterating over my dataset to get it into the desired form. How might I optimize or ...
3
votes
1answer
42 views

Checking tag colors

I have an array vs.tags which may contain hundreds of objects, and a smaller array coloredTags which only contains up to 3 ...
7
votes
2answers
78 views

Series sum calculator

This is my program currently to calculate sum of following series: $$\frac{x^2}{2!} + \frac{x^4}{4!} + \frac{x^6}{6!} \dots$$ ...
7
votes
2answers
46 views

Shell sort function

I wrote a Python sort function that uses shell sort: ...
18
votes
4answers
1k views

Performing and timing loops

I am a casual C# programmer, not formally trained in OOP at all; mostly I focus on Transact-SQL in SQL Server, and so when I write C# apps I get grief about the constructs and methods I use. Here is a ...
2
votes
1answer
61 views

Counting occurrences of sorted elements [closed]

Forgive the hard coded test data - but I'm looking to make the inner while loop disappear, or at least simplified so this code doesn't run in \$O(n^2)\$. I've been thinking over some ideas of how to ...
4
votes
1answer
48 views

Java 8 find array of countup sums

I have an array of some arbitrary int values; I want to find the array containing the sum of the past elements in the current index. Example: ...
2
votes
1answer
55 views

Fill missing values based on group

I am trying to fill values based on group, in my case id. I would like to fill the missing values according to the available ...
-2
votes
2answers
50 views

Manipulating strings and character positions

Write a program that manipulates two strings. The program inputs two strings (string1 and string2) and a character (...
12
votes
3answers
971 views

Calculating Parking Fees

Here's the challenge description: A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $...
2
votes
2answers
62 views

Calculate number of co-occurrences for two vectors

I would like to understand how to get rid of all the loops I am using in this code. I have a dataframe of 20 rows. I am simply counting the number of occurrences that the variables ...
2
votes
4answers
160 views

Print factors of number using fencepost loop

I was wondering if this code could be optimized in any way? For instance, could I use a for each loop here? Are there other ways I could write this which would make it easier for me, or the person ...
-1
votes
1answer
27 views

Removing an element and the element following from an ArrayList [closed]

I have an ArrayList of Strings. I want to delete all elements with a particular value and the element immediately after that one. I have an ArrayList with the elements "Ape", "Bear", "Cat", "Dog", ...
11
votes
5answers
399 views

Populating a bag of Scrabble tiles

I am filling a bag full of scrabble tiles. There should be 100 tiles in the bag of these letters: ...
7
votes
3answers
195 views

Colorizing Excel cells with a date range filter

In a table there is a number of column (chambre) and a number of row (alveole). If these matches in a list in an other sheet then it checks if it the date is between two dates on that second sheets. ...
4
votes
2answers
222 views

Calculating how long sales reps are idle

I wrote a procedure to calculate the number of months elapsed since a sales agent' last sale. It works but runs in over 10 minutes... for 20 rows. ...
0
votes
1answer
34 views

Retry storing HTTP response into a variable until specific code

I want to keep trying to get response until its code is 200 or unknown yet. In first case it should be stored in response variable. In another case I should raise ...
3
votes
0answers
178 views

Asynchronous iterator for AngularJS

I wrote this as a convenient way to batch together multiple, repetitive AJAX calls. I was working in angular at the time, so I use the $q service, but I'm sure it ...
2
votes
1answer
35 views

Scaling up the intelligent concatenation of 2 columns in R

I've got a huge dataset in R which contains (among other things) 2 columns indicating "Term Code", which are "Term Code" and "Term Code1". "Term Code" is the mostly-correct column, which usually ...
0
votes
1answer
31 views

User and Score models

I have a couple of models - User & Score. I am displaying data from those models to my template. Data from ...
1
vote
0answers
22 views

Searching through rows of paged grid until row is found or there are no more pages

I have a GWT Grid, using a pager, so pages of the grid (table) can be any number of elements long. I'm looking to iterate over every row of each page until I find a row with the matching text in the ...
3
votes
1answer
62 views

Rename subkeys of nested dictionary dynamically

My nested (ordered) dictionary looks like this: ...
-2
votes
2answers
88 views
3
votes
2answers
363 views

Adding a bookmark, or changing an existing one

I have a very problematic nested if/else/for that I'm sure it could use some love. Here's how it looks originally: ...
0
votes
2answers
72 views

Improving code with loops in Java [closed]

I am working in a lemonade stand game in Java I have some conditions to determine the "perfect recipe" I see a lot of repeated code that I am sure it can be improved with a loop but I am having a hard ...
1
vote
1answer
56 views

Using a nonsense string to check if a call has completed, rather than timeout?

My question is whether or not this is a good practice, and/or if there is a more efficient way to do it. I have to access this Solidworks interop object and wait for it to return some value. The ...
8
votes
5answers
444 views

Print Consecutive numbers by comparing two parameters

input 3,5 output should be 3,4,5 input 5,3 output should be ...
2
votes
2answers
100 views

Dictionary foreach loop with multiple occurences

A little look on what are Dictionaries: dictWordCounter<string, int> dictWordPercent<string, double> topTwentySeven<string, double> ...
3
votes
1answer
52 views

Generating realistic terrain data - Part 2

I've made a "heightmap" terrain generator similar to my previous one, except this one has some improvements, and some new features. The way this one works is similar to my last one, but slightly ...
3
votes
4answers
468 views

Find duplicates in List where all the numbers in between is <= than the duplicates

My function is supposed to go through a given List<Integer> and find integers of same value, but only count them if the ...
2
votes
2answers
112 views

Looping through an Array of objects to find an ID in a sub array

I have an Array of objects, each which contain their own sub Tags Array, and I need to loop through and find a matching id. ...
1
vote
1answer
50 views

Character counter

This will go through and create every possible permutation of a username with a length of between 4 and 255 characters. ...
2
votes
1answer
117 views

Convert list of UTC to Current TimeZone

I found myself with a list of UTC timestamps and wanted to convert them into the local time zone. Using this web post as a starting point, I modified the script to grab a text file containing UTC ...
0
votes
1answer
76 views

Refactor nested foreach loop based on object property

I'm using a levenshtein matching algorithm to match a title to a filename (for anime). I either use the main show title for matching or its alternative titles (...
0
votes
1answer
54 views

Word Counting from Array onto Output File [closed]

For this problem, I have to have two text files: one for list of words that need to be found and other containing the document that needs to be search. The results would placed in a output "results" ...
4
votes
3answers
162 views

Minimum coins algorithm in Ruby

I am working on a puzzle to find the minimum number of coins needed to buy a product. I am given three coins: 1 3 5 and also a number representing the price of a product: 11 The answer here ...
1
vote
2answers
78 views

Identifying numeric substrings of an alphanumeric string, and summing them

I am going through the CodingBat exercises for Java. Here is the task I have just completed: Given a string, return the sum of the numbers appearing in the ...
2
votes
2answers
34 views

Returning matching substrings, of n length, at the beginning and end of a string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the longest substring that appears at both the beginning and end of the string ...
6
votes
4answers
616 views

Summing digits of an alphanumeric string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the sum of the digits 0-9 that appear in the ...
2
votes
0answers
48 views

groupJoin() in Swift

I have created the following function in Swift for this library I am writing, which joins two arrays on a key (extracted using given closures), and then groups them by key in a ...
3
votes
1answer
279 views

removeAll(closure) in Swift

From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside ...
4
votes
3answers
78 views

Case insensitively removing a substring, efficiently

I am going through the CodingBat exercises for Java. I have just completed this one: Given two strings, base and remove, ...
10
votes
4answers
816 views

Imaging with getPixel() and loops

I wrote perfectly working code that reads an image, and then does a kind of threshold on it by zone. If the zone has too much white then it turns all the zone into white, otherwise it turns into ...
0
votes
2answers
126 views

Changing algorithm to avoid looping with iterrows

I am new to Python. I wrote a code that works but the algorithm is obviously not efficient at all. I am stuck in the loop on iterrows and I do not see how to get rid of it. First a little bit on the ...
1
vote
4answers
126 views

Redacting everything in a string except a particular word

I am working through the Coding Bat exercises for Java. Here is one I have just completed: Given a string and a non-empty word string, return a version of the original String where all chars have ...