Loops are a type of control flow structure in programming in which a series of statements may be executed repeatedly until some condition is met.

learn more… | top users | synonyms

0
votes
0answers
20 views

Python for loop [on hold]

I have a basic for loop in python that I'm wanting to run whereby I call a function and pass in a parameter that is varying from 480 to 6000 in increments of one...thus... ...
-1
votes
0answers
20 views

Calculating the average of numbers [closed]

I'm working on loop statements and I have to input an integer which states how many numbers to enter, and then find the average of those numbers. i keep getting stuck in the loop. trying to figure out ...
5
votes
1answer
52 views

Date ranges from a given start date

I'm trying to get a certain number of date ranges given a start date. Here's my code: ...
6
votes
2answers
72 views

Foreach-loop for and print commands

How can I make the following code shorter or efficient (maybe with other loops or other nice ideas), and keep the current functionality? ...
7
votes
1answer
68 views

Compute stats on two class vectors

Below is a full working code example of code which is used to compute stats on two class vectors (partitions). There are two functions: pairwise_indication and ...
4
votes
1answer
37 views

Baseline tagger

This is a baseline tagger coed I have written. How can I optimize this code? ...
7
votes
2answers
259 views

Repetitive For Loops in 2048 Game

I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
9
votes
2answers
193 views

Using a Pythonesque range() generator function with the Java foreach loop

Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison. I like the way Python has a range() generator that allows the ...
7
votes
2answers
74 views

Merge some child values back into the parent multidimensional array

This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant. Is there a built-in ...
0
votes
0answers
10 views

Why is i++ “unreachable code”? [migrated]

I'm running a search on a workbook, looking for the sheet that matches all the string search criteria. In the Visual Studio editor, the i++ is underlined as ...
10
votes
5answers
398 views

Refactoring my problem-solution to reduce complexity

I need some help refactoring my solution to the problem below: Problem Statement An Association of Computer Scientists meets on a weekly basis. There is a certain number of seats in the meeting ...
2
votes
2answers
82 views

A matrix with square diagonals and transpose being increments of other

Construct a matrix with the following property: North-west to South East diagonals are squares. Matrix[i][j] + 1 = Matrix[j][i] for each i less than j. Example of such m a matrix is ...
1
vote
1answer
43 views

Construct date sequence in Scala

I want to have a continuous date sequence like ['2014-01-01','2014-01-02', ...] Then I define a stream to do that. ...
7
votes
2answers
112 views

Pulling JSON using jQuery and manipulating the Front-end

My JavaScript is fairly new and want to learn new ways to create clean, fast code. Can you have a look at this code and guide me on how to optimise this code to improve my skills? I have provided the ...
8
votes
3answers
1k views

Brute force password-cracker

I am just coding some classic brute force password cracking program, just to improve myself. I've explained how my program works at the start of the code. Check some of those screenshots to ...
5
votes
1answer
328 views

Mini mind reader

Here is a code that guesses the number chosen by the user. I know that using goto is a bad practice, but it seems unavoidable here. that's because using do while ...
2
votes
1answer
42 views

How to shorten the JavaScript in Raphaël?

The Rapheal script seems to be too long. Is there any option to make it shorter ? I think loop can make this script smaller. Does anyone have good suggestions or ...
25
votes
5answers
3k views

Is it OK to use while ((line = r.readLine()) != null) construct?

I want to refactor the following code because I don't feel comfortable about using assignment inside comparison operator. It looks like pretty idiomatic C, but do you think this is a good practice in ...
3
votes
3answers
130 views

Loop optimization for image processing

I have this piece of code that is running too slow. I was wondering if anyone can help me optimize it as I can't seem to find any more shortcuts. I'm not sure if using ...
18
votes
3answers
3k views

Is my coding technique progressing in terms of C# loops?

I have isolated a little bit of code that was causing a small debate between myself and another user. I have taken some of the things that he said and meshed it with the code that was being reviewed ...
-2
votes
2answers
104 views

Is this correct way to use loops or should it be in LINQ?

The results variable is coming from an API that have a arrays in arrays, etc. I have made a foreach with ...
11
votes
9answers
2k views

Is there a more succinct way of writing this simple JavaScript loop?

This seems a bit redundant to me, but I'm not sure of how else I might be able to write this. Normally I'd use a switch statement, but I don't think that'll work ...
7
votes
2answers
380 views

Object Creation during loops

I'm trying to parse a CSV file into objects. I've already got a very efficient CSV parser (SuperCSV). The problem arises when trying to create the object with the data that is being read out. I've ...
7
votes
3answers
91 views

Collect and calculate average times from log, then display top 10 longest durations

Here's a novel-length summary of the issue: I'm trying to write a VB.net program to help me collect remote site statistics from system-generated logs, but I'm a little like a carpenter who only knows ...
9
votes
1answer
160 views

Making C++11 range-based for loops a bit more useful

C++11 is great. Probably one of the most beautiful features (in my opinion) is the so-called range-based-for-loop. Instead of ...
4
votes
1answer
159 views

Building <div>text</div> inside a while loop [closed]

I use the following code <div><?php echo $obj->text; ?></div> in while loop. Is this the best way? Is there a better way, either to optimize ...
5
votes
1answer
76 views

Game Loop and FPS

Some time ago I made my simple game loop, so here's the code: ...
5
votes
1answer
42 views

Read line and combine duplicate entries based on one of the fields

The following Java code reads lines from an input text file and will output the entry that has the highest number in field-2 to an output file: INPUT: William J. Clinton 6 Q1124 42nd President ...
5
votes
2answers
270 views

QuickSort of Comparable[]

Here is the code for the QuickSort class that I created. ...
10
votes
2answers
130 views

Thread-safe prime number source

I am working on some multi-threaded code that requires a prime-number source. The following code keeps an array of primes in memory, extending it as needed. It works in the 'int' domain, being ...
3
votes
1answer
56 views

Display PHP Menu Stored in an Array and Looped

I'm creating a PHP website for a non-profit. They have some restrictions (no MySQL or pre-installed CMS) so I'm creating a CSS menu displayed by an unordered list where all of the elements are stored ...
6
votes
1answer
133 views

How to fill an ArrayList of ArrayLists with a Left Join?

I have a class Employee that contains an ArrayList of Projects. I'm storing the Employees in one table, and the Projects in another. I'm trying to find the best way to create an ArrayList of ...
0
votes
1answer
77 views

Time Limit Exceed Problem [closed]

When I submitted below code in codepad.org, it shows "Time limit exceed" problem. Please provide alternative solution : Problem Statement : Given a number K, find the smallest Fibonacci number that ...
6
votes
2answers
2k views

Read an input text file and store the tokens in 2 different arrays

I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the ...
7
votes
1answer
135 views

Creating a thread for file transfer

I am creating an application in Java that runs at scheduled intervals and it transfer files from one server to another server. For SFTP I'm using ...
10
votes
5answers
1k views

Printing star greater symbol in Java

I need to print this in Java. I have written code for this, but I feel that my code is too big. * ** *** **** *** ** * My Code: ...
21
votes
5answers
2k views

Print an ASCII diamond

This takes a width specified by user and prints a diamond of that width. It uses only three for loops, but could I reduce that further? Is there a more elegant ...
2
votes
2answers
60 views

Optimizing Python code for Project Euler #5 (LCM of all numbers from 1 to 20)

This is my solution for the 5th problem of Project Euler, which asks for the least common multiples of the numbers from 1 to 20 (inclusive). Is there any way to improve the while loop conditional ...
40
votes
11answers
8k views

Nesting versus GOTO: which is better to avoid?

In Java they're not really known as GOTO statements and are rather referred to as Branching Statements, but I find that the former term is a bit more indicative of ...
1
vote
2answers
48 views

Managing while loop in bash

Two difference scenario in bash program, First Here i am breaking loop in function testFunc. ...
18
votes
6answers
4k views

Guessing a unique 4 random digits number

I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...
8
votes
3answers
87 views

List iteration, creation, or comprehension

I suspect that this can be done in a much neater way using list comprehension in python: ...
3
votes
2answers
59 views

Find end of $.each() loop

I need to find the end of a loop or the length of the object. Some context on the code: I obtain the txt var from the DOM (that's the only way I've got by now and ...
11
votes
3answers
430 views

Creating all possible combinations of points

I want to create all possible combinations of points (0,0),(0,1)...(12345,6789) and then all segments from these points. The code I have written is simple and with no optimization. Is there any ...
3
votes
3answers
417 views

Decrease CPU usage in while loop

I've a application which runs with two threads. The main thread runs in one infinity-while-loop: ...
3
votes
1answer
59 views

Math Skills Game Advice

I think my code works pretty well, although I'm biased: http://jsfiddle.net/AHKb4/2/ Basic Overview: I'm working on building a math skill game, where the objective is to drag and drop div's to a ...
1
vote
2answers
99 views

How can I remove this for-loop in this competitive FizzBuzz code?

I'v written this code snippet that's part of a code competition. I want to do the trick without the for-loop, or simply find a way to optimize this code for speed. ...
4
votes
3answers
286 views

Do-While loop in Python, with limit on the amount of 'do's

I'm in a location with poor Internet access. In order to ensure that a call to an external service succeeds, I am wrapping the call in a pseudo-do-while in Python. ...
4
votes
1answer
52 views

Locating empty field groups for saving data

The aim of the code below is to see if selected fields are empty so data can be saved in that field. Since I'm making a library system, I wanted to record the basic info on one record (all the books ...