Newest 'loops' Questions - Stack Overflow

Questions tagged [loops]

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.

0
votes
0answers
9 views

iterating over pandas dataframe, geocoding, takes forever?

I have a dataset with ~10k entries, and I cannot request the coordinates for all of them each time since that would take very long. So the idea was to set the first row values, and then iterate over ...
1
vote
2answers
14 views

list iterating exception so the loop keeps going, geocode

I have a list of place names and I want to iterate over it to get the coordinates: import time from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent="xxx") for a in pl: location ...
2
votes
3answers
44 views

Sum of prime numbers for large range input

I am writing code to find the sum of all primes below a given number (in this case I want to find it for 2000000) My code will run just fine for numbers like 20000 and lower, but as I add 0s to it, ...
-1
votes
0answers
10 views

How to fix 'reference not set to an instance of an object' inside foreach loop of HTML Agility Pack [duplicate]

So i have foreach loop inside one while loop which needs to run five times, first time everything is ok, second time does not work and i have this error: "System.NullReferenceException: 'Object ...
0
votes
3answers
32 views

Subtract values in pairs of two in a sorted dictionary

I am still pretty new to Python and am trying to automate something I do manually. I have a sorted dictionary consisting of 6 items. The size of the dictionary will always contain 6 items, where the ...
-1
votes
0answers
20 views

Modify the variables contained in the loop list [duplicate]

I discovered that it is impossible to modify variables which are included in looping list while looping over them. To give you a simplified example, assume the following two constants a = "hello" b =...
0
votes
1answer
38 views

PHP - Is there a way of looping through all elements in a JSON file if I could only fetch 100 items at one call?

I need to display all the elements/objects of a JSON file. I can currently only call an endpoint that takes an offset (starting index) and limit. The maximum number of elements you could get is 100 (...
0
votes
2answers
42 views

keep checking if value in array is array

I want to create a loop that prints a array as a '' but also keeps checking if the value is an array as well so that I can loop through that array too. But I don't fully understand how I can keep ...
1
vote
1answer
30 views

How to loop input field value and insert to its row based on the database value in Laravel?

My problem is that I want to update the quantity_served based on quantity and insert the last loop value into the last record based on the input value. For example, my input value has 180. My code ...
-1
votes
0answers
13 views

Calculating the Factorial of a Number and getting the final number in a message box [duplicate]

I am stuck on a problem from my Visual C# text book. The question is as follows; (omitting the part about how factorials work) Create an application that lets the user enter a nonnegative integer and ...
0
votes
1answer
31 views

Is there a way in VBA to find a String in a Directory and then Loop?

I have partially solved my problem below. Over the course of the day, I want to increment my files by 1. Currently, I can just increment my files with the same name (same string) by 1 if Excel ...
0
votes
2answers
58 views

Novice question - Why does this loop not work?

I assumed the following code would merge all different lines of user's input into just one string. The results are different. What is the logic behind this happening? I was hoping to unite different ...
0
votes
1answer
23 views

how to get multiple values from textfield inside a for loop and recive it in an array

im pretty bginner at java , what i want to do is user gonna say how much numbers he will input so i save this number in a varieabale for ex: he wants to input 5 numbers so int x= 5; then i want to ...
0
votes
1answer
24 views

How to create a dataframe with a for loop over years in csv

I have csv files for each month and year from 2015 to 2019 and am trying to read them into a single dataframe and create a year variable that distinguishes each year so I can eventually merge them. ...
0
votes
0answers
16 views

multiple urls using a for loop in scrapy

i want to scrape information from multiple urls. I use the following code but it doesn't work. May someone please points me to where I have gone wrong? import scrapy class spider1(scrapy.Spider): ...
-2
votes
1answer
53 views

Why is this code outputting so many numbers? [duplicate]

Starting with two arrays a and b, I am trying to output a matrix c with dimensions sizeof(a) and sizeof(b), whose entries are the product of every pair of the Cartesian product of a and b. Theses ...
-2
votes
1answer
29 views

How does a for cycle loops trough items, if you delete and add one item mid-loop?

I've wondered about this, on word 2007 this didn't work as I expected, and on word 2016 it did. Let-me explain: I have a for loop For i = ActiveDocument.Sections(1).Headers(1).Shapes.count To 1 Step ...
0
votes
1answer
33 views

How do I create a financial program where I can continuously input amount and show remaining amount in dollars

Trying to create a financial calculation program. I know I have to use loop but how do I loop continuously when the user input float value? I believe I'm wayyyyy off but I am quiet curious how this ...
3
votes
2answers
54 views

Reading function input values defined in `…` from an CSV file in R

Suppose I have an R function like foo below. This function has 4 fixed arguments, and any number of arbitrary arguments defined in .... All input values for foo arguments are stored in THIS CSV file....
1
vote
2answers
28 views

I want to print 1 to 10 counting in a text file using php

I'm trying to get 1 to 10 counting in a file using PHP loops but that does not work how can I fix this code I'm running PHP 7+ and I tried to use for loop and they then used the increment variable ...
-1
votes
1answer
16 views

I have trouble adding more than one product-line to a cURL call when reading lines from mysql

I have a number of orders in a database, each order can have more than one orderline. I have to send each orderline in a curl-call, and I'm having trouble when I have more than one orderline. I ...
-2
votes
2answers
35 views

PHP: Nested loop with only unique pairs

I need to create an array of only unique pairs so there are no duplicates. The problem is that when just iterating over each other, for some reason last pair usually is duplicate. So here's a quick ...
0
votes
1answer
41 views

Extracting same rows from multiple df´s and create new df

I want to extract 13 rows from my data frames (different years, all equal). And then create a new df with only these 13 rows for each year. Is there a way to solve it with a loop? Or to apply it to ...
0
votes
2answers
43 views

Trying to get string outside LINQ .SelectMany statement

I got a solution where i need to make a calendar for artists on a festival. I found a way of sorting them with .SelectMany().OrderBy().ThenBy().ThenBy() Now i need to get out of a loop (ItemPublisher:...
1
vote
3answers
50 views

Iterate through nested objects to form a string

I have the following array, containing multiple nested objects (the nesting level could be infinite) : var logicRules = [ { 'operator' : null, 'conditionString' : 'x == y' }, ...
0
votes
0answers
38 views

while True loop script stops running, no termination or error thrown

From running this code on a loop, it doesnt terminate or seem to end? No error is caught / thrown. It always does it once it is on line 189 on the output console. import time from requests_html ...
2
votes
1answer
40 views

How to fix this ' float not iterable ' Error

I'm Solving the Problem set of MIT's introduction to programming. def compute_deriv(poly): """ Computes and returns the derivative of a polynomial function. If the derivative is 0, ...
-3
votes
0answers
31 views

Use handler in a for loop java [duplicate]

I am trying to use a handler in my for loop in my java code but it keeps saying i should make the counter variable final but i dont intend to do so because i will have to increament the value. I saw ...
0
votes
1answer
80 views

How to establish a symbol, a character as a condition for loop

I'm trying to put a loop on my code(a simple calculator), where it restarts if you try to divide some number per 0. I'm here for hours but can't manage to see the problem. I'm a beginner by the way. ...
-3
votes
1answer
39 views

In a dictionary, find the keys with the most values in common

I don't know where to begin. The following instructions were given: Find the actors that have the most movies in common. Output all ties. Solution uses the name_and_movies dictionary that associates ...
0
votes
0answers
12 views

Running a loop using Logistic Regression

I have 3 datasets I'd like to run a logistic regression on split into X1, y1 X2, y2 X3, y3 How can I run a loop so that I can run an automated logistic regression using the X_train, X_test split ...
0
votes
0answers
13 views

loop for extract bands from multiple .tif file

I have 94 .tif hyperspectral images and each one have 63 bands. I have to store in a separate list all single bands for all the .tif files here is the list that contains the raster files setwd("D:/...
1
vote
2answers
38 views

extracting one set of multiple variables in a list of data.frames in R

Suppose I have a data.frame like THIS. Any columns of data after the column named autoreg are arbitrary columns defined by the user. So, I won't know the columns names or values. For example, in THIS ...
1
vote
2answers
39 views

Is my analysis of this code correct, and why would it be written in this way?

I inherited a python program (more like a large number of scripts) that I'm rewriting into an OOP program. I'm still learning Python and ran into this line of code which I am uncertain about. ...
0
votes
1answer
23 views

How do I use values within a list to specify changing selection conditions and export paths?

I'm trying to split a large csv data using a condition. To automate this process, I'm pulling a list of unique conditions from a column in the data set and wanting to use this list within a loop to ...
0
votes
3answers
39 views

How to avoid double iteration, and printing the statement 2 times

I have this piece of code, where it prints the numbers from 0-24 and it prints you need a break when time is equal to 8, 16, 24, now the point is when time is 8, 16 and 24 it prints the time and the ...
-1
votes
0answers
25 views

Foreach return 524 error on large data in php [on hold]

I have an array of more than 9000 data, when i loop through it then it gives me Error 524. Basically i have to send user an email based on their skill.
4
votes
3answers
58 views

Array base address is changing when declared inside loop

I declared an array inside for loop and tried printing its base address. #include<stdio.h> int main(){ int n=16; for(int i=1;i<=n;i++){ int a[i]; int b[16]; int c[n]; ...
0
votes
2answers
56 views

Create 10 lists and assign each 10 values in one loop

I have a DataFrame sized as 2 columns ; 'ID' and 'name'. And 100 rows (ID from 0 to 99). I want to create 10 groups as lists and put into each, 10 IDs. For example, group0 = (0,10,20,30,40,50,60,70,...
0
votes
1answer
35 views

Forming a new dataframe from the old data frame using for-loop

My data frame "c1" steps interval <dbl> <int> 1 0 0 2 0 5 3 0 10 4 0 15 5 0 20 6 0 25 7 0 30 8 0 ...
-1
votes
1answer
29 views

Remove Goto statements

I need to optimize a code and I would like to remove the goto by loops but I have a little trouble with the proposed loops and the VBA syntax! Dim a As Integer, b As Integer a = 2 line1: 'Goto ...
0
votes
0answers
17 views

What is the difference between using for loop and schedule?

I wish to understand the difference between For Loop and schedule. I'm using Typescript to create a spin button and I want the button to spin unlimited times, during the process I found out this issue....
-1
votes
1answer
20 views

Clarity on definition and iteration of objects in functions

I have practiced functions, methods, classes, objects before. I need more clarity on exact method to define and iterate here. I want to understand the difference between definition and when a code ...
0
votes
0answers
11 views

change value matrix with looping [duplicate]

I have same problem, iwant to change value if matrix[i,j]=NA change to 1, else matrix[i,j]=1 change to NA r1_matrix<-as.matrix(cldmsk_final[[1]]) nr <- nrow(r1_matrix) # nrow = 100 nc <- ...
0
votes
0answers
15 views

For loop in scipy optimization (SLSQP) usage

I wanted to know python code for how to write variables, constraints and objective function using for loop as I want values for different i's. #for variables for i in range(sup): def calcCost(K): ...
0
votes
1answer
38 views

how to loop a for loop 5 times that is already looping a python code in subprocess?

code: import subprocess import json my_dict = {} for i in range(10): x=subprocess.Popen(["python","first.py"],shell=True, stdout=subprocess.PIPE) output = x.communicate()...
1
vote
1answer
40 views

My data from my loop is being mismatched, not sure why

I have a code that is suppose to display messages back and forth between the users. For some reason the data is mismatching and I'm not sure where in my code I have the error. I've tried to change my ...
0
votes
2answers
38 views

How to loop through multidimensional arrays with deffierent lengths - PHP

I'm trying to loop through a multidimensional array. Each array's sub-array has a different number of values. How would I loop through this to output a list item for each cars' value? $cars = array ( ...
0
votes
1answer
44 views

For loop inside another for loop crashes in Javascript

I want to randomly generate a color for each pixel in the canvas however my loop seems to crash the browser and I cannot figure out why? I have tried reducing the loop to a static number (X = 10 x Y=...
0
votes
2answers
24 views

ACF get_field not returning value

I'm trying to use get_field to return a simple text field and it returns empty for some reason. A field itself is where it should be and there is text in it, so that part is all set. This PHP code is ...