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

Keep running batch loop after starting .exe

My program.exe sometimes stops. I have made batch script that checks if program is running and start it if not in loop. The problem is loop is exiting after program.exe is started and runned. I need ...
2
votes
1answer
26 views

Multiple borrow in previous iteration of loop

Following is the code I'm working on, I explore a directory path with a queue and I want to store the filesystem tree in my data structure (the enum Entry): use failure::Error; use std::collections::...
0
votes
1answer
16 views

for loop in method vue js and replace caract

I must display data that i set in my user model, I get the info from the database but encode in html format. I have already tried a lot of things like deserialize my json to put in the right format ...
1
vote
0answers
7 views

While conditions with an and inside

Hi I am trying to run the following code to access a Raspberry Pi in a follow the line robotic car The goal is can these while if elif work ? i tried to read about it but still not finding the ...
1
vote
1answer
36 views

Better way to split list of integers based on values and rules

The goal is to split a list of integers based on each element's neighbors, based on these rules: (the current/focal value is smaller than or equals to the previous) and (the current value is equals ...
1
vote
1answer
27 views

Nested loop or equivalent

I am trying to make a nested loop, I start with a simple loop and I would like make the same with differents data frames; This work fine: set.seed(123) df1= data.frame(date= 1:10, ...
0
votes
2answers
31 views

Is there a way to loop back to a previous line of code in Python v3?

I'm new to Python, and I was wondering if there was a way to loop back to a previous line of code? command = input('Choose [a]dd, [d]elete, [l]ist, [s]earch, [v]iew or [q]uit: ') if command == 'a': ...
0
votes
0answers
19 views

Is there a way to loop an R classification model while swapping out one variable?

I'm basically trying to do what is described in this question R Loop for Variable Names to run linear regression model (i.e. swapping out one independent variable while all others stay constant) ...
-1
votes
2answers
33 views

How do I loop until the user put the correct input on java?

I'm writing this program and I want to display the message "Invalid machine number, please enter again" when the user puts a number that is not between 1000 and 2000. I'm trying to loop until the user ...
1
vote
2answers
48 views

simplify nested for loop in c#

I need help in simplifying a nested for loop or is it the optimal way already without adding more complexity var multiParamValues = new Dictionary<string, string[]>(); multiParamValues.Add("...
0
votes
0answers
19 views

Looping over multiple dataframes to calculate required task (Equal-weighted portfolio sharpe ratio)

I am wanting some help in looping over multiple Dataframes. The code below generates the required output for the 10 industry portfolio. I could simply change the variable of dfxsind to dfxsmom to ...
0
votes
3answers
49 views

Unable to exit while loop (as data validation) while testing for string input in homework problem in C++

I'm trying to write a simple program where I see if a user qualifies for a loan. I'm trying to do validation to make sure the user doesn't enter gibberish, and when I do, it doesn't exit the while ...
0
votes
1answer
19 views

How to convert a csv file into a json formatted file?

Most of the samples here show hard-coded columns and not an iteration. I have 73 columns I want iterated and expressed properly in the JSON. import csv import json CSV_yearly = r'C:\path\yearly.csv' ...
1
vote
1answer
29 views

R: Loop through columns, select value from a column and write it to a new column in same row

I have dataframe in following format id var1 val1 status1 var2 val2 status2 var3 val3 status3 123 a 12 false b 23 true c 34 true Here I want to go though each column of ...
0
votes
0answers
8 views

how to search for two value in range collectivly in VBA Excel

The code has got a searching order and what it does is as following: It takes each value in ws.range A and looks it up in another sheet named wp.range A. If a particular value x in ws.range e.g A3 is ...
0
votes
0answers
16 views

Create buttons in a loop and set array elements as title

I want to create some buttons in a for loop and found the solution to push the buttons to an array and then use this array within my view. That works well so far. But I can not manage to set the array ...
0
votes
1answer
34 views

Can I return value found in this any iteration?

I'm teaching myself python and I'm making some changes to a bot that someone else wrote. I'm trying to add a filter for words that NSFW or not kid friendly. I've added these words to a list called ...
0
votes
0answers
17 views

How can I make an arrow shape to loop between a list of names by pointing at each name daily/weekly in Excel?

Basically I'm trying to make an arrow or a color in a cell to move through a list of names in specific cells on daily or weekly basis in an Excel worksheet. The purpose is just for an indication to ...
0
votes
0answers
29 views

Looping through 3 different SQL results

I need to loop through 3 results of SQL queries. The problem is that it's only bringing the fist result, instead of all of them. exports.rewardsNotifications = function() { var now = new Date() ...
0
votes
0answers
30 views

How to loop a function based on the result of previous iteration

I have a linear-plateau function. I want the function to exclude y-values smaller than 10% of the maximum reached (meaning the y-value for the plateau) and iterate until no changes occur (i.e. no ...
0
votes
0answers
34 views

I am trying to create multiple loops but if one loop returns null it doesn't run the rest of the loop. How do I get around this?

I have multiple for loops in one code, as I am trying to collect data based off identifier "Y". There are some sheets that do not have identifier "Y" and those sheets always cause my script to stop ...
2
votes
3answers
46 views

How do I make a nested loop continue only after a asynchronous function has been resolved or how do I extend “.then” beyond the scope

I tried to prevent async problems with promises in the following code. By using a .then function everything within that function gets called after the function has been resolved. But now I have the ...
-1
votes
0answers
41 views

How do I loop / can I loop a hashmap put()?

I have an Arraylist with Vehicle properties and I needed to store them in a "car park slot", so I have decided to use HashMap to store vehicle slot with the vehicle registration, for example "1 = ...
1
vote
1answer
28 views

PHP for loop with Database and API Data only calculates 1 result

I try to loop trough a php script to calculate a Total Holding of a Persons Portfolio. But my code only puts out one calculated field instead of all from the Database. My DB looks like this: id ...
-2
votes
1answer
23 views

Using apply() instead of iterrows on Dataframe rows

I have the following Dataframe, and I am trying to calculate a indicator: Date saldo 0 2018-01-02 94.0 1 2018-01-03 92.0 2 2018-01-04 90.0 3 2018-01-06 86.0 4 2018-01-07 84.0 5 ...
1
vote
1answer
14 views

Get chars after last , (comma) country

I want to get last chance of comma (,) in a $country. But how do I do it? foreach ($countries as $country) { $country_id = $country['ID']; $country = get_the_title().", "; //comma echo "<...
2
votes
2answers
53 views

Java lottery program, having trouble comparing outputs

I have to do an 'instant lottery' program in my first computer science class. All semester my professor has read verbatim from the book, so now I am a little lost, truthfully. I know how to do most of ...
-2
votes
1answer
19 views

How to stop look returning None when there is an element that satisfies if condition?

I am looping through a list of booleans my conditions are if the position of the element is > m and if the element = True the function will return the position of the element this is what I've ...
0
votes
2answers
43 views

How to fix that at filtering an multidimensional array, the array gets more elements?

I have an multidimensional array called "Places" like this: 0: Array [ 1, 1 ] 1: Array [ 1, 2 ] 2: Array [ 1, 3 ] 3: Array [ 1, 4 ] 4: Array [ 1, 5 ] 5: Array [ 2, 1 ] 6: Array [ 2, 2 ] 7: Array [ 2, ...
0
votes
1answer
23 views

When/how is the “memoryview()” function used?

I came across it in my autocomplete when I started typing the name of a variable that began with m, what is it used for and when/how should it be used?
0
votes
0answers
7 views

MongoDB collection.find() to return chunks of n documents

Say i have a DB of 2 million documents and i would like to iterate over all of them. I would like to process batches of n documents at once since i'm using a function as such: def work(self,items): ...
1
vote
2answers
31 views

Multiple data in one user input

I am having a trouble with multiple numbers in one user input. The idea is to multiply each user`s number with a predetermined one. Does it even possible to loop through? in1 = input('Enter ') in2 = ...
-2
votes
1answer
49 views

C++ program not decrementing correctly

So, I am making a program where you can add marbles to a bag. You choose the color you want, then the number of marbles you want to add, and then if that color marble is either cool, boring, or weird. ...
0
votes
0answers
40 views

how to create a loop that create sub lists and add elements to it

want to create a loop that can create sub lists in a big list and add values from a text file to this list for example i have a text file that contain this data name text1 text2 text3 text4 text5 ...
-1
votes
2answers
45 views

How to take second array from while loop in JAVA

I write this code using JAVA to get data from URL, it works but I confused how to take the second data from the result in while loop, public static void main(String[] args) throws Exception { // ...
0
votes
0answers
19 views

async.eachLimit done function turns to var

when i use async.eachLimit with an async function as the callback, done element which is function to get to next loop becomes a variable async.eachLimit(items, 1, async (item, done) => { var ...
-1
votes
0answers
32 views

How to loop through a multidimensional array and insert into a SQLite3 database

I need to loop through this array and insert it into a sqlite3 database. The array is: $array1 = array( array(1, "Epson", "Color", 12), array(2, "Xerox", "BlackWhite", 45), ...
-1
votes
0answers
20 views

How to view the grandchild of an an array in Blade using laravel?

I am trying to fetch the results of the grandchild of an array and display it in the Blade. There are two arrays:- array:2 [▼ "Block A" => array:49 [▶] "Flat C" => array:100 [▶] ] As ...
0
votes
0answers
48 views

why use q = (i * 52429) >>> (16+3) rather than q= i /10 in the Integer of java?

In the source of Integer of Java why use q = (i * 52429) >>> (16+3) rather than q=i / 10? for speed? static void getChars(int i, int index, char[] buf) { int q, r; int charPos = index;...
-1
votes
1answer
53 views

How to loop through multi-dimensional array and enter into SQLite3 db

I'm trying to insert the contents of my multi dimensional array into a SQLite3 DB. My array looks like" $array1 = array ( array(1, "Car1", "Truck", 14), array(2, "Car2", "Sedan", 45), array(3, ...
0
votes
2answers
26 views

Tkinter - For Loop too early

I have a code for a "Magic Mirror" where I want to display clock, title and news (in Japanese). I have a whole code that works fine with a news code inside it - In Tkinter loop - news code takes ...
3
votes
4answers
77 views

Get previous number in loop when saved to variable

still new to learning JavaScript. I want to loop through some values. If value is greater or equal to a certain number, then break the loop and get the previous number. For example: var time = [...
0
votes
2answers
41 views

How do I arrange loops?

I am new to Python programming. I am trying to make a program that helps sailors quickly calculate their speed, time, and distance using the handy formula S * T = D I created If statements based on ...
0
votes
1answer
75 views

How to get the values from the loop to the blade - laravel

I used for loop to fetch a query and able to store in a array. The array for eg: looks like when i: dd($s); array:2 [▼ "Block A" => array:49 [▶] "Block K" => array:149 [▶] ] Now with ...
0
votes
1answer
18 views

How to properly use if…else statement in conjunction with a for loop?

I have two arrays. I have to display both arrays and then find common integers within them. If there are any, display them. If there aren't display 0 or write an outpu I have the for loops to do it, ...
0
votes
0answers
20 views

nls: Loop and break in a decided number of iterations

I've like two make to sequential operations: 1) Ajusted two nls models in a subset; and 2) Loop the models just a number of iteracions =1. For the first step I make: #Packages library(minpack.lm) #...
2
votes
1answer
47 views

Javascript loop - move DOM element by X pixels in Y milliseconds

I have a loop that needs to end at a certain time labeled by the variable milsec, however, the loop is not performing slow, causing the time to not end correctly. How can I fix this so the iteration ...
2
votes
1answer
69 views

ConcurrentModificationException When removing element using list iterator java

I have an issue removing the 1st and 2nd element of my list even by using the iterator. I have read the following threads but can't fix my issue (those were the most relevant but I checked other ...
-1
votes
0answers
15 views

MenuManager, FileManager and how to get these classes to work together and loop through arrays? [on hold]

I am working on a MenuManager project with a FileManager class and a MenuManager class, the point of the FileManager class is to manage the txt. data and MenuManager is working to create the Menu's ...
-1
votes
0answers
44 views

Can't get echo to output message at the end of script

I have a script that looks at a user and tell you how long the user is online. but at the end I can't make it output the message the user isn't a valid user. If they aren't a valid user then nothing ...