Questions tagged [loops]

20963 questions
1

votes
1

answer
35

Views

Iterate through properties in a loop

I'm trying to loop through a row of data for a set amount of times to access a different property every time. The data looks like this: [JsonProperty('Afbeelding')] public string Afbeelding { get; set; } [JsonProperty('Afbeelding_2')] public string Afbeelding2 { get; set; } [JsonProperty('Afbeelding...
Michelindoll
1

votes
0

answer
117

Views

Loop through Dictionary in Swift

I have a dictionary which I want to append some items. **This is my dictionary which I want to achieve: ** let parameters: [String: Any] = [ { 'ResultsList': [{ 'UserId': 'b806e283-066f-4081-aafe-1fe216a57c35', 'FriendUserId': '7a2ec150-cdb3-4600-84f8-2dab970bfa0c', 'TransferDate': '2017-11-23', 'U...
Ziyaad
1

votes
0

answer
199

Views

How to skip to next iteration if no results are returned in SELECT statement in Stored Procedure?

I have a case where I SELECT rows from one table and INSERT them to another table. However, I get Error: 1329 SQLSTATE: 02000 if the SELECT statement doesn't return any row. Can I do something like: CREATE PROCEDURE SP() DECLARE CONTINUE HANDLER FOR NOT FOUND; BEGIN ITERATE END BEGIN DECLARE cur1 C...
swdon
1

votes
1

answer
70

Views

looping a string inside replace() method in JavaScript

I have two strings, the second string, as being converted from an array, containing NaN objects. I try to replace each NaN with a character from the first string, using replace() method. Although looping through a string goes well in a separated function, when I insert it as a second argument to the...
user2751869
0

votes
2

answer
29

Views

Looping through a list of Objects is not displaying properly

I'm trying to display a loop of objects. It's showing through console.log, but it's not showing on the browser. My current code is as follows: class Profile extends React.Component { renderList() { const { booking } = this.props; booking && Object.keys(booking).map(x => { console.log('booking',...
Kevvv
1

votes
1

answer
81

Views

Java - 2-Do-While Loops in a For Loop

I'm quite new to programming so excuse my basic and limited understanding. Essentially, I am creating a Memory Game for a school project. I want to do 2 do-while loops in a for loop that works like this: the user will be prompted to enter a 4 random letters which will be done in the first do-while l...
JotNation
1

votes
1

answer
64

Views

R Programming Newbie! - Median Loop Function Broken

So the function below is using a really big dataframe. Two columns of this DF are the year houses were built and the other is the cost. I want to input the column name, in this case ds$Built as the function argument YearCount
Mitsugi
1

votes
0

answer
52

Views

Incrementing a variable 1 time in a loop for further checking with an if

So I have 2 questions regarding those 2 ifs in my code. So, firstly I want to check if fail is superior to 7, but it doesn't seem to work If the value of the variable fail is superior to 7 it would increment its variable by 1. The way it works is that there is more code behind it which sets up a wor...
1

votes
1

answer
25

Views

.htaccess rewrite causes an endless loop

I have a .htaccess code the rediredt every user on smartphone to a competible website: RewriteEngine On RewriteEngine On RewriteCond %{QUERY_STRING} !^desktop RewriteCond %{HTTP_USER_AGENT} 'android|blackberry|googlebot-mobile|iemobile|iphone|ipod|#opera mobile|palmos|webos' [NC] RewriteRule ^ h...
1

votes
0

answer
60

Views

Breaking out of a critical region (but not a parallel loop) in OpenMP

I am running nested for loop, with the outer one parallelised, and I am wanting to break the inner loop #pragma omp parallel for default(shared) private(found, i, j) for (i=0;i
Dant
1

votes
4

answer
99

Views

Loop notification to every user

I'm trying to send a notification to every users thats assigned to a project. I can get all user id by doing this $ids = array_column($users, 'id'); $userid = implode(', ', $ids); echo $userid; But when I trying to put it insida my function nothing happened. It just blank. I have also tried to move...
Fredrik J
1

votes
1

answer
246

Views

Excel VBA loop through cells to find Conditional Formatted cells and copy paste on other sheet

My issue: I want to loop through a range, and whenever it finds a conditional formatted cell, it should copy the cell to the left to the cell to the right of it. And then afterwards paste it into an other worksheet. My code loops through the cells easily, but doesn't copy the information, and paste...
Patrick S
1

votes
1

answer
30

Views

Unable to Iterate Columns of a Selection — error '424' Object Required [closed]

I'd like to be able to loop through the columns of a selection and do arbitrary things such as set column widths through some calculation. However, all of the variations I've tried that run-time error '424', Object Required. I've dug through the documentation, these forums, and Google, yet the cl...
Nil Rift
1

votes
0

answer
306

Views

Print Loop results of each iteration

I am working with CTM for Text Mining and I'm running a loop to define the optimal number of topics, using the following code: best.model
Pedro Oliveira
1

votes
0

answer
48

Views

Assign NA to cells according to sum of column and row index for each cell

I am dealing with a data frame and should assign NA values in cells, if sum of the row and column index for each cell bigger than a certain value. df 10){ df[j, i]
plotly_user
1

votes
0

answer
31

Views

NodeJS storing iterator position over requests

We have written some code that returns an array from a database and on the first request, we loop over it until we find the variable. and then send that value. However, if we also have a second request that request starts iterating at the position we left the previous loop on. result.findAllLights(f...
noahp78
1

votes
1

answer
74

Views

Batch File: For loop variable dropped after goto invoked in nested for loop

I'm trying to write a batch file that, for a set of numbers (1 to 10), starts an executable sequentially. The numbers from the set of numbers are being passed to a file for the executable to run in batch mode. However, because the executable hogs resources, I want only 5 of these executables running...
Taylor Steele
1

votes
1

answer
218

Views

Using concurrency in nested for loop? (Brute force) [closed]

I'm adapting code from a C program I made in class & I'm trying to convert all the programs I've written in C into Go in order to learn the language. I'm not quite 'getting' concurrency yet though. How would I apply concurrency to a nested for loop? The current iteration of my program is SLOW, much...
Frank Jaeger
1

votes
1

answer
67

Views

R expand.grid but with prohibitions

I have a list of items v1, v2, etc. Important: its length is NOT known in advance!! Each item (v1, v2, etc.) shows possible levels: 1:2, 1:3 etc. I need to create a data frame with all possible combinations of levels for items v1, v2, etc. I could do it quite effectively using 'expand.grid': mylist
user3245256
1

votes
1

answer
64

Views

optimising loop in python

I am new to Python. I am trying to do the following loop and wonder if I am doing it the correct way or if there is a better (faster) way to do it. Briefly, i want to compute a series of conditional mean of a variable y. The conditions are created with regards to the x variables. For example, there...
T. Li
1

votes
2

answer
34

Views

Adding arguments into array by loop

I want to create script which will create directories. User has to pick how many directories he wants to create, and then has to name those directories. I already have something like this, but I stuck and don't know how to add arguments into array by loop.. Could you tell me how it should be? #!/bi...
Marcin A
1

votes
1

answer
1.1k

Views

Get item value in a loop with failed tasks in Ansible

There is a one interesting thing I try to perform with Ansible but something goes wrong. Example: A text file contains IP addresses of some hosts. I need to read each line in the file and check whether SSH port is open for every IP address. If I get a timeout while checking host port then I should k...
Semka Mesilov
1

votes
0

answer
27

Views

Append Open List from Dictionary

I have created a csv file containing zip codes and corresponding vendors in those zip codes. CSV File Image Download CSV: https://www.dropbox.com/s/8hm6yvy9gviydcv/us_postal_codes.csv?dl=0 I wrote some code to convert this into a dictionary. What I want have is an input zip code prompt so that the...
paulie
1

votes
1

answer
659

Views

openpyxl write multiple rows in Excel

I am trying to write multiple rows to Excel. 'Containers' has an index/len of 10. Although I loop through it, I only get one row when I run the script. Can anyone help me with this? # define first empty row start_row = sheet.max_row + 1 #write to excel for container in containers: #Company name comp...
Renier
1

votes
1

answer
392

Views

Loop calculations in Python [duplicate]

This question already has an answer here: How to return multiple values from a function? [closed] 14 answers I'm trying to build an entropy function from the scratch as asked by my leader. I have a dataset Ttrain, with many variables, sex being one. I'm having to extract the categories(male and fem...
IndigoChild
1

votes
2

answer
57

Views

R Which repetition of loop produces a value larger than the critical value

I have this function gillespieLO = function (N, n, ...) { tt = 0 x = N$M S = t(N$Post - N$Pre) u = nrow(S) v = ncol(S) tcrit = 2 tvec = vector('numeric', n) xmat = matrix(ncol = u, nrow = n + 1) xmat[1, ] = x for (i in 1:n) { h = N$h(x, tt, ...) tt = tt + rexp(1, sum(h)) j = sample(v, 1, prob = h)...
Gragbow
1

votes
1

answer
438

Views

Swiper.js Custom Pagination Name

Using swiper.js v4.0.6 I would like to display custom names on a pagination bar using the renderCustom API. I need to display three slides, and their corresponding names which I have set using data- attributes in the HTML. I have most of it working, but the item names aren't displaying in the correc...
TheOrdinaryGeek
1

votes
1

answer
47

Views

comparing two cells in certain pattern VBA

I'm trying to compare two excel's cells in certain pattern using VBA. The table is separate by empty rows. And the patter is: I'm looking at column A. If cell A1 is empty I'm moving to next one. If cell A2 is not empty then I'm compering $A2$ to B2, B3, B4, .. etc until I hit the empty cell. If so,...
Grzegorz Pyko
1

votes
0

answer
243

Views

VBA Set Workbook does not assign correctly when workbook is already open

This might turn out to be a beginners question, I think I am missing something basic here. The user selects different Excel-files, which names are stored in the String array fileNames. The macro is then meant to crawl through the selected files and translate a specific worksheet to XML. Application....
cr44sh
1

votes
0

answer
38

Views

How to clear an object of list after it gets processed once with iterator

I have one method which is writing is processing csv file as below: public void processFile(Mapper mapper) { List outputDataList = new ArrayList(); Iterator iter = this.addressLists.iterator(); while (iter.hasNext()) { List listOfAddress = iter.next(); for (AddressDto address : listOfAddress) { this...
user9193174
1

votes
0

answer
308

Views

How do I iterate a Zillow API call / output parse function in R over a list of addresses and zip codes?

I've been working on a project where the goal is to take a two-column CSV of street addresses and zip codes, read it into R, then perform a Zillow query for each one (GetSearchResults, specifically), parse the output, and store the parsed output in a dataframe to be written to a CSV (and placed righ...
Sean
1

votes
0

answer
16

Views

Refactoring code that evaluate only specific values in a Ruby hash

I have a long hash, consisting of some hashes within hashes. Right now I just need to evaluate only a select few of the hash's values. if params[:my_hash]['start_date(1i)'].empty? || params[:my_hash]['start_date(2i)'].empty? || params[:my_hash]['start_date(3i)'].empty? || params[:my_hash]['start_da...
Misha Krul
1

votes
1

answer
230

Views

Error in Parsing Json to Dataframe R

I am getting below mentioned error while passing Json dataframe. Error in data.frame(Addr = 'London', companyName = 'Eagle SUITS', : arguments imply differing number of rows: 1, 0, 2 In addition: Warning message: In data.frame(Addr = 'NA', companyName = 'SAMTEK ENTERPRISES', : row names were foun...
Vector JX
1

votes
0

answer
21

Views

How to change a name of a database in a loop?

I am struggling to change a name of database in a loop (lines 47-49). What the program is doing - it prompts a user to enter a country and automatically download the data of a stock index from Quandl database. However, once I do this, I want to call data frame like 'data_country'. Please, advise me...
Alberto Alvarez
1

votes
3

answer
79

Views

Loop changing background color with switch in javascript

So I've been trying to make this switch, it's simple in my head. stating a variable 'num' equaling 1 to begin with, setting an 'if' or 'while' statement for when 'num' is equal to 2, the background color of a certain div will change from white to yellow and back in .5 second intervals. My problem I...
Tyler Lancaster
1

votes
2

answer
122

Views

Check minimum value in loop for python

I have these arrays: A=np.array([160.592625, 161.616830, 161.672708, 163.544365, 163.745786, 164.260333, 164.277012]) # points on x-axis B=np.array([53.090028, 54.829213, 54.573222, 47.244701, 52.033966, 48.613694, 53.425587]) # points on y-axis I create the arrays of (x,y) coordinates: coord =...
user23299
1

votes
2

answer
46

Views

Finding the difference between the dates in months based on particular ID and solving in R

Below is my sample data set which has many unique ID's and I have to find out the difference between the first occurrence and the second occurrence in the First_Diff column and the difference between the second occurrence and the third in Second_Diff column and so on. They are many occurrences in th...
Zhoe
-1

votes
0

answer
21

Views

How do I get it to loop until all elements are parsed?

I have a hashmap containing 6 elements as I have - E : [x1:0.4, x2: 0.5 , x3: 0.56, x4: 0.45] - What Im trying to do is to over each element, until the E is empty. The problem here is that it retrieves the first min, and stops, yet the E hashmap still contains elements, what is it that I'm missing...
Muna Ar
1

votes
1

answer
64

Views

I keep getting the wrong numbers from my program

I am trying to write a program where the user inputs 2 dates and the program calculates the days in between (without using any of the calendar classes) and prints the results, but I keep getting crazy numbers that make no sense. When I tried to make it calculate 5 days it printed the results of 333...
Thomas P
1

votes
1

answer
53

Views

PHP MySQL performance advice

I have a table called house. The table house has 32 columns (id, name, floors, doors, color, windows etc. etc.). So basically a table with different columns of different data types (varchar, int, decimal, enum and so on). Now let's say the table has 500,000 rows. And now I have my users. They can...
rwur

View additional questions