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
2answers
52 views
3
votes
2answers
329 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
59 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 ...
2
votes
1answer
48 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
368 views

Print Consecutive numbers by comparing two parameters

input 3,5 output should be 3,4,5 input 5,3 output should be ...
1
vote
2answers
79 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
41 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
266 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 ...
1
vote
2answers
61 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. ...
-2
votes
1answer
35 views

Text-to-Morse Code translator [closed]

I'm curious if anyone can come up with a better code structure (loops, checks) than what I have done. I need to change the structure because my teacher was unhappy with the for loop and if else's for ...
1
vote
1answer
48 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
28 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
40 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
30 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
103 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
43 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
33 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
417 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
37 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 ...
2
votes
1answer
83 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
64 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
711 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
95 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
99 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 ...
2
votes
1answer
50 views

Project Euler Problem 52: Permuted multiples

This is my solution to Project Euler Problem 52 - Permuted Multiples. In the problem I'm searching for the smallest value of x such that x, 2x, 3x, 4x, 5x, and 6x use the same digits. ...
6
votes
1answer
459 views

Cutting The Sticks

Problem Statement This is a challenge from HackerRank: You are given N sticks, where each stick has the length of a positive integer. A cut operation is performed on the sticks such that all of ...
5
votes
1answer
216 views

Counting occurrences of substring in string

I need to know how many times a substring occurs in a given string. I figured that I might as well create an extension method: ...
2
votes
2answers
51 views

Assembly Summation Implementation

I wrote a simple summation program in MARS to practice using loops and jump instructions. I feel like this is pretty lightweight and wanted some feedback on possible improvements: Lowering ...
2
votes
0answers
91 views

Genetic algorithm for the minimum of the Schaffer function

I have to implement a genetic algorithm in R to optimize the minimum of the Schaffer function. Below I describe each step and I need to create one big function and another loop for 100 iterations (and ...
1
vote
2answers
52 views

Increasing FPS of updateMobs

I am starting to experience frame rate issues in my game and I've tracked it down to my updateMobs function. I would like tips and code examples from you guys to ...
4
votes
2answers
61 views
0
votes
2answers
135 views

Array to Tuple in Swift

I am burdened with the requirement of interacting with a C based library, which has a bunch of constant sized arrays (e.g. char[17]). When trying to assign or read ...
0
votes
1answer
62 views

Reduce nesting of for loops to increase efficiency [closed]

I need to optimize this code so it can execute faster, even if that means using more memory: ...
7
votes
5answers
228 views

Reserving seats in a movie theater

I'm writing a C program to reserve seats in a movie theater. I am validating the selection of seats: ...
4
votes
4answers
192 views

Custom Sum implementation

There is a custom summary function needed as to receive an integer input (e.g. 32456) and returns 3+2+4+5+6. Can you think of ...
1
vote
1answer
95 views

Populating an HTML combo box by looped concatenation

This code takes the results of a database query and uses them to populate the options in a combobox on a form. Would it be better to start with an empty htmlCode ...
6
votes
1answer
43 views

Is there a better way to split out join'd table data?

Consider the following segment of code: ...
4
votes
1answer
50 views

Check input from user

Aim: Read in the userID, check if the userID has 10-digits and check if it not exists in database, when both right, the program will leave the loop. This code works on my project, but I think its not ...
1
vote
2answers
83 views

Show first n elements of array, and count elements not shown

This code mimics the "likes" tooltip from Facebook. Given an array with the list of users that liked the content, it shows the first n users and displays a final item with the count of the users not ...
2
votes
2answers
82 views

Refactoring a loop through repetitive registers

I use NHibernate to search for data in the table Register. It contains monetary registers, incomes and outcomes. Some registers are repetitive, so I have managed to implement a few properties that my ...
4
votes
1answer
97 views

Render/Update game loop

I've just "finished" my second attempt a core game loop, which is a heavily refactored version of my first attempt. My perceived benefits are: Using functors means that the actual loops themselves ...
3
votes
3answers
88 views

Simple list comprehension

As far as I can tell, there is no network access happening at this stage in the code. I am accessing Reddit's API via the PRAW module. However, it is crawling, and I think it should be faster, ...
3
votes
1answer
37 views

Do my Image Widths Exceed Limit?

I needed to find whether any image's width at or higher than a certain directory folder exceeds a limit. Is this code a good way of doing this, or is there a way in which it can be improved? I ran ...
3
votes
1answer
43 views

Calculating solutions for the game “24”

I was bored this evening and decided to create a program which calculates all the solutions for a given scenario of the game "24". The goal of this game is that you try to be the first one to find ...
8
votes
3answers
153 views

Collection that can be modified in a foreach

Sometimes you want to add/remove items from a collection inside of a foreach loop. Since this isn't possible, a common pattern is to add the items to a separate ...
3
votes
3answers
127 views

Sieve of Eratosthenes in C#

Just because I've never written a real Sieve of Eratosthenes, I decided I should probably write one just to make sure I know what it is. I'd like (constructive) criticism on best practices, potential ...
2
votes
1answer
34 views

Calculating top position of elements based on their heights

I have a data representing several elements (that could be rendered at some point as div), composed of y position (property top) and its height (property height). ...
1
vote
1answer
91 views

Lodash chain implementation

I am mainly trying to avoid the nested forEach statements and am trying to move towards a lazy evaluation type solution. jsFiddle ...
4
votes
2answers
407 views

Non-recursive method for finding a ^ n

I am working on an interview question from Amazon Software. The particular question I am working on is "to write a program to find an." Here is my recursive solution to this problem (in Java): ...
6
votes
3answers
421 views

Nested loop to render tiles in a grid

This code works but I'm not really sure if I wrote it good enough. It seems a bit vague but I can't really assess it properly. I'm particularly concerned with the ...