Category "for-loop"

How do I take the users input and have the program loop that many times for a for loop? [closed]

How do I take the user's input for how many legs are on the trip and have it loop that amount of times? int counter = 0; int gas = 0

Setting name of current file being read as variable

Using a for loop in a batch file, from a folder full of xml files, I am trying to parse an xml tag but also the file name of the current file being read. I have

How to create objects from a dict where the keys are the name objects and the values are the attributes? Using a loop

class Cars(object): def __init__(self,brand=None,color=None,cost=None): self.brand = brand self.color = color self.cost = cost ima

JavaScript How to create elements into each created element?

I'm trying to put a content div into each parent div, but this way it puts all the content divs to the first parent div, not each parent div. I've tried to do i

PHP array filled by a MySQL query [closed]

I need to fill multiple different arrays by using a MySQL query. This would have up to 16 different arrays. I want to specify each array with

Iterate Opening a List of URL's with Selenium

I am having trouble iterating the action of opening a list containing URLs using selenium. the issue is in the part labeled #Second Part in my code. linklinkfin

set.seed in for loop

I'm doing some analysis and I had to impute some values. To do so, I write this chunk of code: A) set.seed(1) for (i in 2:length (Dataset[-c(8,11)])) { D

dopar% and %foreach% failed to work for gmapsdistance

I am currently trying to apply parallelization with the gmapsdistance package (driving mode = bicycling) to speed up the computation of the for loop that contai

Finding max consecutive 1 in a given array (leetcode)?

class Solution { public: int findMaxConsecutiveOnes(vector<int>& nums) { int ctr = 0, max = 0; for(int i=0; i<nums.size(); i++)

How do obtain max and mean values from different columns with a Date column condition in R?

I am trying to get the daily mean and maximum values for each pollutant. For each of the monitoring stations, the daily mean and maximum values of each pollutan

Return Array After For Loop

Having a hard time understanding for loops in arrays. Trying to create a Thank You card creator and these are the steps I'm trying to follow: Create a new, empt

Printing multiplication table using arrays and nested for loops

I am working on an assignment to create a multiplication table using a 2D array. This is what I came up with. 'use strict'; window.addEventListener('load',

Save Data to Array Variable in For Loop

I need to find the earliest & latest dates for certain table entries. A link to a diagram of the table. The premise is that every time an entry has a desire

How can I get the output as a scalar value not a vector from this function?

I am writing a function to find the definite integral of any function by using the Midpoint method, the output of this function must be a scalar value, where y(

Is there a more efficient way to calculate the difference in months in R

I have a large data frame in a panel structure (201720 rows; 3 columns) which looks as follows: Name <- c("A", "A", "A", "B", "B", "B") Inception <- c(as

Iterating over a dataframe twice: which is the ideal way?

I am trying to create a dataframe for Sankey chart in Power BI which needs source and destination like this. id Source Destination 1 Starting a next point b 1

MATLAB: How to convert data from an excel file (several sheets) to a matrix?

I try to process data from an excel file from several sheets (~200). Luckily the data is always at the same position in each sheet. I wrote the following code f

R : How loop a function creating named dataframes according to dataframes contained in a list passed in argument?

I made a function that takes a dataframe as argument, and creates two dataframes in output according to a threshold value of one of the columns. These 2 output

My python def's doesnt work as expected when called, why?

I'm a bit stuck because I've already written those functions in Java and they work properly, and then, when "converted" to python, they didn't work as expected.

how can I use if condition inside the loop in r

I defined a function creates 3 random numbers from 1 to 36, and I allowed repetition. I want to test how many times I can get three same numbers in one hand in