Questions tagged [for-loop]

A for loop is a control structure used by many programming languages to iterate over a range. It is a way of repeating statements a number of times until the loop ends. Depending on the language this may be over a range of integers, iterators, etc.

0
votes
0answers
10 views

For loop storing values in MATLAB

I have asked a similar question before, see, Double for loop in MATLAB, storing the information I am storing the results from a for loop but this time my number do not increase by one each time. %...
0
votes
0answers
11 views

Creating time series with loops and populating them with values

I have a data frame, where each row represents a part of the time series. I need to create a total time series that stretches over several years, for up to several hundred units. So, each row sets ...
1
vote
1answer
60 views

charAt() giving me bad output

I am making a programming language, and where semicolons are in javascript, slashes are in mine. Here is the code: document.getElementsByTagName("input")[0].addEventListener("change", ...
0
votes
0answers
10 views

Linux scripting - Looped search with large file

OS - Centos I have a file with a list of telephone numbers - numbers.txt I have another file that is an export of a database table with 1.8 million rows - export.txt In export.txt there is a column ...
0
votes
1answer
29 views

For-loop, calculate predicted movement, delete row if outside range

I have a data-set containing vehicle movement, where vehicle time and position is logged with GPS. The issue is that there exist duplicate values (spoofing) for several of the vehicles, and I am not ...
1
vote
5answers
40 views

function doesnt print out all the even numbers?

I have to write it this way with two functions for class but am having trouble printing all the even numbers instead of just 1. def is_even(the_value): if the_value % 2 == 0: return True else: ...
0
votes
1answer
30 views

Nested loop with different Magick command in bat Windows

I am trying to convert many pdf files into jpg but only if it has 1 page. I rather work with multi-pages pdf than images. I tried different command and get them working correctly individually, both ...
2
votes
1answer
57 views

JavaScript - For Loop to add days in a month object - moment.js

I'm trying to assign every day in the month to my object but I'm only get the last day of each month. How should I do to get full month assigned? function loopRange (startDate, range) { let ...
0
votes
2answers
31 views

Python- Taking away brackets from the function call?

I'm writing a function that takes 1 argument, and I want the argument to be a list. I've gotten basically all of the behavior I've wanted except or ONE thing:` def index_responses(a): j = {} ...
-4
votes
1answer
23 views

How can I console.log the name property of the objects in the shoppingCart array using a for loop [on hold]

var shoppingCart = [{ id: 0, name: 'Mens Shirt', price: 20, size: 'Large' }, { id: 1, name: 'kids shirt', price: 15, size: 'small' }]
0
votes
2answers
22 views

Jquery- How to get the same number in two nth-child tags?

for (var i = 0; i < 3; i++) { $(".rain:nth-child(" + (i++) + ")").click(function() { $("li:nth-Child(" + (i++) + ")").css("opacity", "1"); }); } I have 2 tags, li ...
1
vote
4answers
44 views

How does Java handle using a getter on a for loop?

For instance, if I have the below for loop declaration. for(Foo f : fooService.getFooList()){} Is it more efficient to call the getter first and assign it to a temporary List<Foo> fooList = ...
0
votes
3answers
33 views

Subset data in a for loop - R

How can I do the following operation in a for loop? x <- runif(30, 0, 1) sub_1 <- x[1:10] sub_2 <- x[11:20] sub_3 <- x[21:30] That is, I want to create three different objects, each one ...
0
votes
0answers
18 views

How to create a loop with considering combination of columns in R

My data set looks like this: My goal is creating many attributes by combining current variables. For example I want to create an attributes which called HS_POC, This attributes shows Yes when we ...
-2
votes
0answers
21 views

The target type of this expression must be a functional interface error while casting for loop

userInt = scanner.nextInt(); for (int y = 0; y <= userInt; sum + y;) { } It gives the error "The target type of this expression must be a functional interface inside the for loop ...
1
vote
2answers
57 views

Are empty for loops in PHP considered bad practice?

I'm currently writing a bit of code to shift the values of an associative array to the right in PHP 7.0, and have used a for loop with no instructions in it: $array = array("one" => 1, "two" => ...
0
votes
4answers
33 views

function inside a setTimeout gives undefined

I want to set some wait time after each api calling. So I have added setTimeout for api calling in for loop but it giving api service that is createAPIService undefined in setTimeout. Below is my code....
0
votes
0answers
35 views

Probability scores for distribution of two means

I have a 40-long list of means and variances relating to model error rates. I am looking to determine which models are statistically better (smaller error rates) than others. Assuming error rates are ...
-2
votes
0answers
40 views

For loop in a single line

Here a simple question; I need to skip from this: for i in range(64): y[:,i] = RLS_EEG(b[:,i],a) to something like this: y[:,0:64] = RLS_EEG(b[:,0:64],a) but in a way that they work EXACTLY ...
1
vote
3answers
28 views

Test presence of elements in each row and column of a 2D array - java

I written a short program that randomly populates a 10x10 2D array with 0s and 1s. I want check the array to see if each row and column contains more than five 1s. I've done it using 2 separate ...
-6
votes
0answers
35 views

php for/while repeat insert sql [on hold]

i would create a for or while, i don't : i have a select, each option has a number in value (1 -> 10) according to the value, repeat an insert sql the basic soluce for($i = 1; $i <= 10; $i++) ...
-2
votes
0answers
16 views

Python; io.TextIOWrapper' skips for loop

In this program I'm trying to open a file and replace certain values with those given in the dictionary. I've added all the print values for debugging. However, only one of the for loops work, it ...
0
votes
2answers
44 views

scala - how to flatten nested optional when using for loop with futures

I'm performing a for loop on a range which yields a future of an optional result. I want the resulting collection to only contain non-optional items . But I'm left instead with Future[Seq[Option[...
0
votes
0answers
32 views

Spark Python: How to calculate Jaccard Similarity between each line within an RDD?

I have a table of around 50k distinct rows, and 2 columns. You can think of each row being a movie, and columns being the attributes of that movie - "ID": id of that movie, "Tags":some content tags of ...
0
votes
0answers
19 views

subsequent php array problem when creating next request to server

This script working fine for me but Only issue I can see is that the proxies stop generating after hitting a254, and it won’t jump to the next server. So you if you’re on a230 and generate 50 it stops ...
0
votes
3answers
47 views

Appending a list through if condition in python

This could be a very basic question, but I realized I am not understanding something. When appending new things in for loop, how can I raise conditions and still append the item? For instance: ...
-2
votes
2answers
42 views

For Loop through Vector Gets stuck last iteration [on hold]

I have a vector of a custom class. All I'm trying to do is iterate through the list element by element. I've tried using indices and now I'm using an iterator. Without fail it gets stuck on the last ...
-7
votes
2answers
55 views

conditional statement in loop c++

for (i = 1; i <= a; i++){ for (b = 1; b <= i; b++){ cout << "X"; } cout << endl; } if a=4, the result would be X XX XXX XXXX while the output of this for (...
0
votes
0answers
28 views

Nested Loop Python - unexpected EOF while parsing [duplicate]

Having a problem with the following code. When I run the first for loop, there is an error which reads "unexpected EOF while parsing". I've looked this up and not understanding where I am going wrong....
-1
votes
2answers
41 views

Loop messing up pattern in Java?

I seem to be having a bit of trouble with my loop. The first part of the loop works fine, but the second part isn't printing out the correct number of spaces. It should start at (N - 1) * 2 spaces and ...
2
votes
2answers
53 views

cant reach for loop with while loop python

Even tho I searched a lot in here for the while loop, still cant find my problem! mylist = [] user_choice = input(' 1: Make a list\n 2: Delete a list\n 3: Delete elements from a list\n 4: Quit\n ...
-1
votes
0answers
35 views

For Loop in C Programming Language [duplicate]

How can ıt possıble? Could you guys explain me! I don't understand how ıt can be 3 there ?? #include <stdio.h> main () { int i; for (i = 0; i <= 2; i++) { int i = 8; ...
0
votes
1answer
49 views

Simple for loop, if statement and output message

I think this one is pretty simple, but I am new to this, so I am not sure where to go from here :) I have a Google Sheet, with some data (pretty large sheet). I want a script that check whether the ...
0
votes
2answers
26 views

Multiple plots in R on a pdf with a loop

I think I need help with the loop. How would you do multiple plots on separate pdf pages with the data below: pdf page 1: Mazda RX4 2 panel plot for mpg vs cyl and mpg vs vs pdf page 2: Hornet 4 D 2 ...
0
votes
0answers
25 views

Efficient substitution of stacked for-loops

I have run into an efficiency problem when calling for arguments of a large array. My Code is: import numpy as np from itertools import product %%timeit z=20 A=np.arange(-z,z+1,1) M=list(product(A,A,...
0
votes
0answers
8 views

How to print each character of a string inputted by the user using a for loop statement?

I am still a newbie when it comes to Java, my lesson is now at String Methods and we have this exercise at school where we are asked to Write Java Statements that will ask the user to enter a ...
-1
votes
7answers
59 views

Python - why isnt my function outputting 'a' ten times? Beginner question

def testfunction(): for i in range(10): return('a') print(testfunction()) I want 'a' outputed 10 times in one line. If I use print instead of return, it gives me 10 'a's but each on a ...
-6
votes
2answers
34 views

Python : compare in looping

I have an array that look kinda like this A = [1, 2 , 3, 4, 5, 6, 7, 8, 7, 6, 5,4,3,2,1,0,1,2,3,4] Edited: I tried doing with for looping and while I can't seem to get it right For u guys can see the ...
1
vote
0answers
33 views

How to make nested purrr map to extract rows based on dynamic variables instead of nested loop?

I have a data frame as below: ## Please copy following text in your clipboard (do not copy this line) hid ,mid ,aprps,astart ,aend ,ax ,ay ,exph 10001,1000101,3 ...
0
votes
0answers
22 views

How to properly select and filter data line in Python?

How to remove unwanted line no. 8 from the result after filtering using below programme??. The actual result should not pick up whole line in month '10'. month=('11','12','1','2','3') newfile = open(...
0
votes
2answers
24 views

How do I print the same output multiple times, horizontally and vertically, in a grid?

I can print a single pine tree of varying sizes, but how do I print an exact replica of it next to it and underneath it, in a grid, using only for loops? This project utilizes a scanner so that the ...
0
votes
3answers
35 views

Stop PHP for loop after 5 valid results

I have a PHP for loop that brings in an array of 11. Currently, the loop prints out all 11. But in middle of this for loop I have an if statement that checks another value, so in the end, its possible ...
0
votes
1answer
25 views

using the NumberFormat import in System.out.format

I'm doing a program on compound interest for a school assignment. I tried using System.out.format(); and used money.format to format the variables investment, interest, and investTotal. I don't know ...
0
votes
0answers
86 views

for loop segmentation fault [on hold]

I'm very new to programming and sorry if I am not asking a question properly on here. Every time after this for loop is done iterating, it gives a segmentation fault. I'm not quite sure what I am ...
0
votes
1answer
46 views

Image segmentation using corresponding masks in python

I have corresponding masks to the images that I want to segment. I put the images in one folder and their corresponding masks in another folder. I'm trying to apply those masks or multiply them by ...
-1
votes
2answers
35 views

Java program to print largest number while continually accepting input [on hold]

I need to create a program that prompts the user to enter an integer and then prints the highest one entered so far (e.g. "enter a number: 5 The higest number so far: 5, Enter a number: 6, The highest ...
5
votes
4answers
56 views

How to correctly use group_by() and summarise() in a For loop in R

I'm trying to calculate some summary information to help me check for outliers in different groups in a dataset. I can get the sort of output I want using dplyr::group_by() and dplyr::summarise() - a ...
-3
votes
1answer
35 views

For loop program returns [value]i instead of [value] [on hold]

I made a simple program but it's printing "twoi=..." instead of "two". I tried re-arranging the for-loop in the program: #include <stdio.h> int main() { int i; for (i = 1; i <= 10; +...
0
votes
2answers
32 views

How to rework two simple java methods [SOLVED]

I am writing a program that calculates the total rainfall of a year and returns the total rainfall for the year,the average rainfall, and the months with the highest and lowest rainfall. My code ...
0
votes
1answer
53 views

Loop through ID and array jQuery

I have a checkout page that has some item numbers that show up on the page. I got all the item numbers and put them into an array. Each item on the page has an ID that increases by one (#item1, #item2)...