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
69 views

Computing the distance and weight matrix of a graph

I would like to create an igraph object. First, I set up the size of igraph object — n, m, then create a random matrix. As a result matrix ...
3
votes
0answers
36 views

Convert A for loop in R to apply function

My goal is to iterate over a datamatrix, calculate mean, standard error of the mean, and then have a bar plot representing the 2 groups of my data matrix in R. My code below works as a for loop. ...
2
votes
1answer
61 views

Generating calendar months for a datepicker

I got a problem I'm finding pretty hard to solve. I'm trying to generate calendar months for a datepicker but at only 12 months I see a perf of around ~4-7ms. This doesn't sound like a problem but it ...
1
vote
1answer
66 views

Getting employee details according to the role

Here is my issue.I have two classes: ...
7
votes
1answer
89 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
6
votes
2answers
41 views

Creating a list of new areas for patches of conserved land within a watershed

I'm writing code to create a list of new areas for patches of conserved land within a watershed based on the current size distribution of conserved land patches that are in the watershed now. I'm ...
7
votes
1answer
80 views

Path finding algorithm using recursion in Python

Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal. In the maze defined, ...
3
votes
2answers
70 views

Loops to merge documents and renumber pages

I have a for loop implementation for merging documents and page re-numbering. But since I am modifying the collection while iterating, I suspect that the code might ...
0
votes
1answer
14 views

Python 3 - better iterate over list or over range of indexes? [closed]

Using Python 3 (3.5 to be exact), I want to iterate over a two-dimensional list. I have the choice to either iterate over the list content directly, or to iterate over the list indexes (...
4
votes
2answers
75 views

Picking the top 5 results for each individual

For loops are the devil. I can't see a way to speed this up with apply or other more speedy functions though... ...
5
votes
1answer
59 views

ExcelVBA loop exports data from spreadsheet to table within Excel

I want to nest a for loop to cycle through the Range.Value but ("B4") throws me off and this can't be avoided. I was considering using an array to do this but ...
1
vote
1answer
78 views

Many CRUD operations for a list of technicians' shifts

The following code snippet is causing me a performance problem in my application. The first 5 db queries are not high time consuming, the real problem lays on the foreach loop. I considered to use ...
1
vote
2answers
55 views
4
votes
2answers
117 views

Balancing the server load

I've created a program that will take, a bunch of numbers from a range of 1 - 255, and then put them into 3 different strings(servers) equally. It does this by ...
5
votes
1answer
47 views

Concatenate data files into master document

Here is code I wrote to concatenate data files into master file. Once the data to be pasted into the master sheet exceeds the number of rows left in the master sheet, the program will create a new ...
1
vote
2answers
56 views

Checking if an element exists in an array efficiently and return it

I am writing a function for my node/angular app that will prompt the user with a random question that he was not asked before. To achieve this I wrote this function: ...
7
votes
3answers
100 views

Searching the same values in an array

If I am not mistaken, this method has a complexity \$O(N^2)\$: ...
3
votes
4answers
111 views

Determining whether a loop iterated at least one element in generator function

I have a case in which I need to determine whether a for loop yielded at least one element: ...
4
votes
1answer
65 views

Powershell zip subfolders recursively, conditionally

This is a progression of the script I posted here: Zip the contents of subfolders, conditionally It does this: Determines all subfolders recursively Checks each subfolder for files older than 31 ...
12
votes
2answers
649 views

Loop round and remove the consonants

The main objective of this code is that you must accept an input from the user and loop and remove the consonants and vice versa and display the new word. I know there is a easier way of doing it, ...
20
votes
8answers
2k views

Writing nested for loops to produce certain output

My task: Write nested for loops to produce the following output with each line 48 characters wide: ...
3
votes
1answer
85 views

Fetching settings for batches of wafers using loops

I have this code below that needs to query multiple database tables. ...
7
votes
2answers
123 views

99 times drunk on Java

This is a rags-to-riches attempt from this question, based on the popular 99 Bottles of Beer, by (lightly) using Java 8's stream-based processing. Any room for improvement in terms of readability? I ...
1
vote
2answers
45 views

2 ways to print a half-pyramid

I wrote this bit of C that prints a half-pyramid, * ** *** **** Here's the main body: ...
10
votes
3answers
363 views

Beer song excercise

I'm reading the book Head First Java and got an assignment to re-create the 99 Bottles of Beer song according to those lyrics found in the URL. I've had to do this with a Java while loop. ...
1
vote
1answer
41 views

Listing EC2 instances

I've got this massive nested for loop with a few if and else statements in nodeJs. The output of all of this is just string which is combined from different values out of JSon object. What I want to ...
1
vote
1answer
23 views

Looping in Scheme

(define loop (lambda (x proc) (when (not (= x 0)) (eval proc) (loop (- x 1) proc)))) Is this the best way to create a loop function in Scheme?
2
votes
1answer
56 views

Cross validation of gradient boosting machines

I am fairly new to Python. I implemented a short cross-validation tool for gradient boosting methods. ...
2
votes
1answer
66 views

Java loop extracting month and year between two dates

I have a ContratMercan with 2 Timestamps containing start and ...
1
vote
0answers
43 views

Looping through JSON object with nested for loops

I've written a function that loops though all of the accounts, properties, views, and filters - each 'level' requires another for loop. I'm working with the Google ...
1
vote
1answer
46 views

Adding column to table in a for loop

I'm running the following code on quite large data frames. I've rewritten it for the iris dataset to make it reproducable. I'm quite unexperienced with the apply ...
1
vote
2answers
74 views

Prime factor tree

Design a program that finds all numbers from 1 to 1000 whose prime factors, when added together, sum up to a prime number (for example, 12 has prime factors of 2, 2, and 3, which sum to 7, which is ...
2
votes
1answer
51 views

Three ways to read a number for a BitInputStream

I'm trying to learn how to write more readable code without introducing easily avoidable performance killers. This is part of a BitInputStream Java class I'm ...
5
votes
1answer
52 views

Slicing time spans into calendar months

I have apparently correct code that still runs for weeks on my data (tens of millions of rows). I show the entire code for reference (and maybe other gains to be made), but the key operation is in the ...
-2
votes
1answer
43 views

Finding the smallest prime number greater than a user input [closed]

As it says in the title, I am trying to find the smallest prime number greater than my input, 'input.' I have to use the following guidelines when creating my code... You program should implement ...
1
vote
2answers
29 views

Assign object keys to another object's keys dynamically

I have an array called viewObject.terms. This array can contain up to 3 items, I need to iterate through this array and save the values into a data object. ie: ...
1
vote
1answer
38 views

For loop step including last value

I've got the following code. I want to loop through my dataset (which is a matrix) in steps of let's say 50.000 and perform biglm on it. ...
0
votes
1answer
156 views

Fetching of JSON data through an API with AngularJS

I have been trying out AngularJS and developing a mobile application to test out its features and I wanted to see if I could somehow refactor to make my JSON response hopefully quicker in fetching the ...
0
votes
2answers
64 views

Using break for nested for loop

I want to apply three levels of filtering on record. rec in cname. rec is string of >2 ...
5
votes
3answers
170 views

Numerology Calculator

I've built the beginnings of a numerology calculator, and would like an experienced javascript developer to review this code. It works as expected, but I can't help but think there is a better way to ...
5
votes
3answers
926 views

Convert Foreach Loop into Linq in C#

I want to convert these loops into simple loop. I want the code to look neat and short. I saw answers related to LINQ but couldn't make out from that. Are there any other possible ways for this ...
-1
votes
2answers
102 views

In VB.NET, does assigning a collection to a variable make a For-Each loop more efficient? [closed]

I have chosen two options for looping through files in a directory. Let me know which one is more efficient (in speed/memory and GC). Option 1: (collect the file name in an array and loop through it) ...
7
votes
2answers
1k views

Countdown clock in Python

This project is from the subreddit for beginner Python projects: The goal of the project is to create a program that allows the user to choose a time and date, and then prints out a message at ...
6
votes
2answers
130 views

2D array to draw a letter 'F'

This is my code to print letter 'F' with nested loop 2d array. Are there changes that could be made in it to make it look better or more efficient? ...
4
votes
3answers
125 views

Getting count value for matched document

I have a list of keywords and I want to count the number of records in a db which contain any one of these keywords. From each record, I want to consider only title ...
3
votes
3answers
59 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? ...
3
votes
1answer
40 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
79 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
128 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
46 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 ...