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
6 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
22 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
21 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
41 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
27 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
14 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
18 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
53 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
32 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
38 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 ...
0
votes
3answers
27 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
34 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 sqlthe basic soluce for($i=1; $i <=10; $i++) ...
-2
votes
0answers
15 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
42 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
28 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
17 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
40 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
32 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
54 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 beXXXXXXXXXXwhile the output of thisfor (...
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
34 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
46 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
25 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 RX42 panel plot for mpg vs cyl and mpg vs vspdf page 2:Hornet 4 D2 ...
0
votes
0answers
20 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 npfrom itertools import product%%timeitz=20A=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 ...
0
votes
6answers
51 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 thisA=[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 rightFor u guys can see the ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,