Questions tagged [loops]

14442 questions
1

votes
2

answer
41

Views

How to enter the strings from prompt into an array?

Here's my code. I've tried a lot of things but it's not working. Please don't give me some complicated code, because I'm merely an intermediate programmer in javascript. So try to make things as simple as possible if you can. Thanks to everyone who helps. function readNumberOfEntries() { var entryNu...
Khalil Hijazi
1

votes
1

answer
517

Views

Loop and merge in Qualtrics - Random & Equal Allocation?

I have a survey on qualtrics currently where I need participants to rate three sound clips of a possible 48. Currently I have it as a loop and merge block, whereby one of the 48 possible sound clips is embedded for each participant - and this is repeated three times. Unfortunately, this means I hav...
Caitlin McCurrie
1

votes
2

answer
790

Views

How to prevent an infinite loop with scanf failure

The Code is supposed to make change for a dollar and works fine. but the professor says that he will be enter random numbers along with letters. It works fine with numbers but when a letter is entered an infinite loop will occur any suggestions? #include #include #define amtPaid 1 #define SENTINAL...
L_Stud
1

votes
0

answer
12

Views

r %dopar% nested loop not running in parallel

I'm running a nested loop via using %dopar% to generate dummy dataset for experience purpose. References link: R nested foreach %dopar% in outer loop and %do% in inner loop sample dataset set.seed(123) n = 10000 #number of unique IDs (10k as trial) , real data consits of 50k unique IDs ID
yc.koong
0

votes
0

answer
22

Views

For loops without increment/decrementing in Java [on hold]

Basicaly I want to print a simple "*" patent, in Java using for loops. I have done exact same code in C and it worked. Those for loops do not have the increment/decrement nominator. For some reason Java doesnt recognize this solution. Any suggestions, why those loops are not recoginzable to Java ?...
kenshin
0

votes
0

answer
19

Views

Menus Looping on Python

for an assignment, I made a menu and must have it work in a way to execute multiple functions. However, the problem is that when I use the menu and put in an answer that doesn't exist, I cannot get it to work correctly. So when I re-enter an option number for "Incorrect option, try again: ", I do no...
AM.AM
-2

votes
4

answer
27

Views

PHP - How to get “all two digits number” that their addition give a specific number

I create a little mind game that need to guess for a number from 1 to 18 the two numbers combination that give this number for example: 1: 10 (1+0 = 1) 2: 11 (1+1 = 2) 3: 12 (1+2 = 3), 21 (2+1 = 3) 4: 22 (2+2 = 4), 31 (3+1= 4), 13 (1+3 = 4) . . . . . . How to get for each number this numbers list en...
max max
0

votes
0

answer
4

Views

Express.js - Check if user already followed and show unfollow button

I have successfully made it so that users can follow each other. What happens when you click Follow is that it will push your user id to the followers of the user you click follow on and then it will push the id of the user you are clicking follow on in the current users following section. Now i am...
-1

votes
1

answer
45

Views

Python: Very slow nested for loop

I have approx. 266680 users (the value of my user_num variable is 266680) and a map with user index key and business index list values. For example: users_businesses[0] = 1,5,7,9,11,15 means that the user with index 0 has already voted the businesses with 1,5,7,9,11,15 index. My task is to create ed...
B.J
1

votes
1

answer
8.6k

Views

Showing nested for loops in a flowchart

How could I show a nested loop in a flowchart? I want to show a nested foreach loop in a flowchart that shows something like this foreach($array as $item) { foreach($SecondArray as $key=>$value) { // Do stuff... } } Now correct me if I'm wrong, but there is no way to show a foreach loop in a flowcha...
M. Salman Khan
0

votes
0

answer
21

Views

Infinite loading with Jquery

I'm making a responsive slider and on some resolution my text doe not fit my slide. I want to reduce the font size in that case but I'd like it to reduce only when necessary. I've made the following code but the page is loading for ever ... Would you have any idea what the problem is ? Thank you...
Pierre Ftn
1

votes
2

answer
250

Views

Comparing the text of different JButtons

I am currently coding a game and part of it consist of having different tiles to be put in a board. I plan on simulating this by having different buttons that will be used to represent the tiles with their corresponding coordinates. For example, one button will say "A1", "A2", etc. What I would like...
ZeldaX
1

votes
2

answer
266

Views

PySpark Dynamic When Statement

I have a list of strings I am using to create column names. This list is dynamic and may change over time. Depending on the value of the string the column name changes. An example of the code I currently have is below: df = df.withColumn("newCol", \ F.when(df.pet == "dog", df.dog_Column) \ .otherwis...
C. Perry
1

votes
2

answer
210

Views

Last iteration on For loop with If condition with twig

So this is only an example of what I'm trying to achieve. I'm looping through all items and print only those, who starts with F and separate them with comma.So in the end, the loop will made, for example 15 iterations, but will print only 5.I'm trying to catch the last one that will be printed, so I...
Vladimir-Manov
0

votes
1

answer
12

Views

How to report overlapping cell values from 2 columns

I have 2 sets of timeseries (dd/mm/yyyy) potentially starting and ending at different periods. I would like to report in another cell all the overlapping dates which are present in both columns. Selecting the 2 columns, created the variables and initiated the "foreach" loop, I don't know the code st...
Overlord84
1

votes
2

answer
34

Views

I expected the loop to copy null character or something but it copies the char from the beginning again. Why is that? How does this loop work?

I am trying to check whether a char array in loop copies the character from other char array which has characters lesser then the number of loop iteration #include [enter image description here][1] #include int main() { int c=0; char a[10],x[5]="hamme"; while(c
Mr Josh
0

votes
1

answer
32

Views

Python append a string with if/else?

I want to create list of result string based on if else result? but currently on 1 value string can be seen when running the loop? example: for ips in npat: ipnet = ips.strip() print ("Processing ..... ", ipnet) fgen = "grep " +ipnet+ " /mnt/hgfs/IRR/fgen.txt" f2pat = re.findall(ipnet,fgen) print ("...
searching1
-1

votes
0

answer
22

Views

Java 8 Nested Loop Modification without using forEach [on hold]

We have a class Field that contains a set of roles. We have a set of fields in a map. We want to filter fields that do not contain certain role as well as whole map entries not belonging to a category. `Map> fieldsByCategories; Map result = fieldsByCategories.entrySet().stream() .filter(e-> e.getKey...
Hristo Penchev
0

votes
1

answer
22

Views

Compare the current element in iteration with all the following elements in an array - for loop

int[] num = new int[] { 20, 19, 8, 9, 12 }; For Example in the above array, I need to compare: Element 20 with the elements 19, 8, 9, 12 Element 19 with 8, 9, 12 Element 8 with 9, 12 Element 9 with 12
Harry
-2

votes
3

answer
25

Views

If statements in loop (python)

I have 20 sectors and want to print my points per sector. With a bunch of if statements it looks like this: if sector == 0: print(1) if sector == 1: print(2) if sector == 2: print(3) ... if sector == 19: print(20) How do I make this shorter and put it in a loop?
helpme
1

votes
2

answer
256

Views

Clojure - Idiomatic Way To Fill A Vector While In A Loop

I have a requirement where upon receipt of a request, I have to fetch values from an external source, filter them and return the filtered values to the caller. I am accumulating the result (until it reaches the required size) by fetching a specified amount of records from the external source at a ti...
Mohamed
0

votes
1

answer
27

Views

How to iterate through a rectangular 2D array and create char[] arrays with backwards (left-leaning) diagonal sections?

I want to use a rectnagular array to create another 2D array full of left-leaning diagonal sections from it. I have read the top answer in this question, and I've tried to make it work for me, but it only shows how to get right-leaning sections. In other words, if it starts on the bottom left, the n...
LuminousNutria
0

votes
1

answer
12

Views

Bash loop - parallelization but also iteration

The target is the following: I have 40 FPGAs in total. 10 FPGAs are connected to a single programmer, i.e., I have 4 programmers to flash all 40 FPGAs. The FPGAs can only be programmed consecutively at each programmer. Now I need a loop which programs all 40 FPGAs. In order to speed up / accelerate...
pallago
0

votes
2

answer
25

Views

Calculating Average length of words using while loop

I am trying to solve a python textbook problem: The chapter is loops so I am pretty sure it wants me to use it and not any other advanced methods. Write a program with a loop that repeatedly asks the user to enter a word. The user should enter nothing (press Enter without typing anything) to signal...
Cruise5
0

votes
1

answer
13

Views

How to display entry from prompt that stops loop

I'm trying to make a page that: Asks the user for their name and displays the user's name on the page Asks the user for a number between 1 and 9, and displays the multiplication table for that number if the user enters a number outside this range, then send an alert with an error message repeat unti...
Cameron Y
0

votes
0

answer
4

Views

Incorrect syntax near \ and GO with user creation loop

I'm hitting a syntax issue with my antislash and dynamic sql exec and was wondering what the easiest way is to correct this loop to denote the \ and whatever other special chars are appearing in my dynamic sql in the below user login creation loop: DECLARE @Domain AS VARCHAR(50) = 'WidgetFactory\' D...
Kevin Henzel
1

votes
1

answer
359

Views

Python tqdm package - how to configure for less frequent status bar updates

I'm using a tqdm package (v4.19.5) for a loop with 200K+ iterations in Python 3.6 (Anaconda 3, Windows 10 x64, PyCharm IDE). It prints the status bar too frequently, so that my earlier history disappears in the console. Is there a way to limit the frequency of status bar updates? I can't seem to fi...
Oleg Melnikov
0

votes
3

answer
30

Views

Largest Occurrence Count

Im new to programming and am stumped on this problem, Ive tried a few different ways with no success. Implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input...
dyertkd
0

votes
0

answer
5

Views

JAVA -> All permutations of a 4 digit string without duplicates

I am kind of stuck. I don't want a code but kind of an idea on where to start or what to use in order to get kickstarted. I don't want a whole solution as it takes the fun away. I know I would need a scanner to input a string/array/int with 4 digits which then should be swapped around in all possibl...
Patryk Sarnik
1

votes
1

answer
36

Views

Do loop in BigQuery

I have a table that looks like this in BigQuery: Type Start_Date End_Date Total_Spend TV 20180101 20180131 10000 Radio 20180107 20180207 5000 And I want to run a query that runs a loop that creates a table that splits each row into a daily table: Type Date Spend TV...
KhalidN
1

votes
1

answer
26

Views

Looping all pairwise comparisons from a list in R

In my R code below, suppose I want to compare all unique 2 m objects using a similar R routine. For example, to compare m1 and m2, my routine is: pchisq(2 * (logLik(m2) - logLik(m1)), df = abs(m1$df.residual - m2$df.residual), lower = F) Question: I was wondering how I could make a function to make...
rnorouzian
1

votes
3

answer
38

Views

Split string of possibly adjacent elements of unknown lenght by type in JS

Given a string (actually a svg path) such as: "M72 0v754h405v-86h-311v-211h302v-86h-302v-285h311v-86h-405z" I want to obtain an array where each element is either a letter, either a full positive or negative number, like this: [M, 72, 0, v, 754, h, 405, v, -86, h, -311, v, -211, h, 302, v, -86, h, -...
Jaume Mal
1

votes
2

answer
31

Views

For loop should add entries to dictionary but only keeps one

This is my very first question here, i've done the research but couldn't really find something similar. Main goal of my script when it's done: I want it to scan all the lines within a text file against a regular expression. If there is a match, the current line and an incremental index shall be add...
Hikari
1

votes
1

answer
55

Views

how do I parse Any in dictionary using swift

I'm not how do it parse a dictionary value which is of type . I'm able to read the key which is string and value is type of Any and has below sample values for given key ▿ 1 element ▿ 0 : 4 elements ▿ 0 : 2 elements - key : nativeName - value : Shqip ▿ 1 : 2 elements - key : iso639_2 - value...
cybergeeeek
1

votes
2

answer
52

Views

How to append in multidimensional arrays using python?

I have two 1-D arrays: tminus = [219 220 225 226 227 332] tplus = [221 222 227 228 229 334] And a 2-D array: t = [[222 224 228 244],[264 280 283 255 346]] How do I append t for the values that are in between tminus and tplus? I am trying to keep t as the 2-D array. I tried: time = [] for k in range(...
Mary
1

votes
5

answer
63

Views

How to loop the split of different cells with line breaks into one cell with line breaks (VBA Excel)

I discovered programming and VBA 5 days ago. I completely overestimated my abilities to master this subject quickly. I am getting more humble now. I really know nothing about the subject. It's bigger than I thought. After two or three sleepless nights I decided to ask for your help. I have a table w...
Patou
1

votes
1

answer
27

Views

jQuery submitting non-stop - infinite loop

I have this jQuery that checks if the value of a text field (id_code) is similar to any of the available values in a select field (id_tipAux). The user should not submit a value in the text input (code) similar to a value that already exists in the select field (types). I am using SweetAlert. Here i...
Gonzalo D'ambra
1

votes
4

answer
56

Views

Replace all values in a list without using enumerate?

Say I wanted to find all the values '6' in a list and replace it with the value '600'. I can accomplish this using enumerate() but I believe this is not a good way to do what I want to do. The problem I am facing is that I need to know the index in order to replace the value with a new one, hence th...
Mike
11

votes
11

answer
363

Views

How can I arrange numbers in this side-to-side pattern?

I am trying to make this pattern in PHP: 1 2 3 4 8 7 6 5 9 10 11 12 I tried this, but was unsuccessful: $num = 0; for ($i=0; $i
Smit Pipaliya
-3

votes
0

answer
16

Views

ask user for 5 numbers then sum them without scanner or console java [on hold]

How do I get ask a user for 5 numbers then sum them without scanner or console in Java? Sorry if I'm not clear enough as I am new to Java. Thanks in advance!!! This is the codes I have so far. It adds, but not like I want. "Please enter 5 numbers." //should ask this question one at a time. int sum =...
SunnyM

View additional questions