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

1
vote
1answer
14 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: ...
3
votes
4answers
74 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
0answers
18 views

PHP 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
33 views

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

Consider the following segment of code: ...
3
votes
1answer
45 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
68 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
66 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
70 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 ...
0
votes
0answers
19 views

JavaScript rock paper scissors [on hold]

So I'm trying to write a loop for the rock paper scissors game if the user chooses a word other than rock paper of scissors but this only works for rock. Does anyone have any ideas? Sorry if this is ...
3
votes
3answers
71 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
31 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
40 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
126 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
101 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
29 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
34 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
387 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
389 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 ...
4
votes
1answer
220 views

Optimizing critical loop for consuming a byte-buffer

I'm currently developing an Open Source project called sims3py using Python2.7. One overarching goal of the project is to ensure a Pure Python implementation of functions currently available only ...
3
votes
1answer
42 views

Perceptron algorithm

This is the Perceptron algorithm, I wrote this implementation with my friend. It gets the job done, but it's quite dirty, perhaps one of you stylish hackers might help me beautify this beast. This ...
8
votes
4answers
366 views

Calculating range of ArrayLists

I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ...
1
vote
1answer
42 views

DRYing out my Sass, looping through selectors

Need help with DRYing out my Sass... there is just so much repetition in here: ...
6
votes
1answer
72 views

Quicker way to go through 550 variables with very similar code

I'm hoping to figure out a faster way to write this before I resign myself to copying and pasting 500 times. I have code here that needs to do tons of vlookup matches. The only thing that changes ...
4
votes
3answers
106 views

Aggregate array values into ranges

In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history? Requirements: I would like a function that takes an array of numbers, and ...
3
votes
1answer
33 views

Variable to byte decaying function

A function that prints out the values of each of the bytes of a variable, which value is given from stdin. Consists of size detector and a loop. ...
6
votes
2answers
131 views

Splitting three comma-delimited strings

I've been reading about loops this morning, to try to improve this snippet of code: ...
1
vote
1answer
50 views

Sort by a custom date field

I've got this code to work, but being really new to PHP, I don't know if this is proper. I've sorted a CPT loop by a custom date. I'm displaying items from most recent (or future date) to oldest if ...
3
votes
1answer
47 views

Iterate over large list of lists and replace its elements

I have a large list of lists, where each list contains words/characters as elements, and each list is of different length and may contain same words/characters more than once, as for example: ...
4
votes
1answer
105 views

Optimizing code to find maximum XOR in Java

This problem is from HackerRank (not a competition, just for practice) Basically what you do is take in two integers as a range and then finding the maximum XOR from a pair of integers in that ...
1
vote
2answers
75 views

Print all combinations

Question: ...
3
votes
1answer
34 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 ...
6
votes
1answer
102 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. ...
2
votes
1answer
91 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
183 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
56 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
123 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
87 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 ...
-2
votes
2answers
107 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 ...
8
votes
3answers
397 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 ...
2
votes
2answers
61 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. ...
5
votes
4answers
576 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
124 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
361 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
71 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
77 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
77 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
103 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
45 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
84 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
64 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 ...