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

sql where statement with range: how to separate by a comma

I'm new to VBA and I'm trying to pull info from a range of cells that will be plugged into the "where" clause of a sql statement. Since it is a where clause, I need to separate the variables with a ...
3
votes
6answers
31 views

Looping String difficulty python 3

The function of this code is to capitalize letter that appears in the even indexed and lowercase the letter that appears in the odd indexed. Moreover, if whitespace appears between the words, the ...
1
vote
1answer
12 views

Matlab: Appending matrices from a cell diagonally into a new matrix of zeros

I have a problem I am trying to solve that creates an Nx1 cell where the data stored inside it are always N number of 2x2 matrices. Example: N = 2 mycell = cell(N,1); for i =1:N; mycell{i} = ...
-3
votes
0answers
30 views

Building an array from a nested array of objects

I am getting this array of nested arrays as response from an Observable { category: string, subcategories: [{ name: string, items: [{ name: string, ...
-4
votes
0answers
36 views

Python - extract values when conditions are true using boolean variable

I'm extracting data from a table and I need to find the item code that meets all 4 conditions. For example, I have the lat and long for this item, the lat needs to be within this range and the long ...
-3
votes
1answer
25 views

Javascript code for pushing input from 3 different arrays to the fourth array to output put “My fullname is '' ” and I live in “”

I am trying resolve the problem where you have three different arrays. The first array has first names stored, second array has last name stored, and the third array has place name stored. The fourth ...
0
votes
4answers
29 views

How to split a string if the delimiter is one or more spaces?

I'm trying to get this to write every word from input in a new line, even if there are more spaces between words, but I can't figure out what is wrong with this. string phrase = Console.ReadLine(); ...
0
votes
3answers
50 views

How do I validate values in the correct range in loops?

I have a question: how do I validate that the value entered in the correct range and ask the user to reenter the choice? I already have the code listed below but it keeps looping instead. For example, ...
0
votes
1answer
18 views

Iterate through an array and convert all character codes to characters?

I've coded myself into a hole and though it would be easier to start again, there is still a lesson to be learned here (it's just practice anyway). I'm building a caesar cipher which will accept two ...
2
votes
4answers
53 views

Mathematical operation to reflect loop iterator about midpoint of number of iterations

Imagine we have a loop with index variable n counting from 1 to 6. As I got through this loop I want to print the values 1 2 3 3 2 1 Is there a elegant mathematical operation (i.e. avoiding if ...
-1
votes
2answers
58 views

While loop repeating too many times

I'm a first year in Computer Science Engineering, and I'm currently taking a Java programming course. It's the first programming language I've ever tried learning and I'm completely stuck. I had to ...
1
vote
3answers
28 views

use of !! in Call Symput in SAS

Could anyone tell me what this data step is doing? I have never seen the use of "!!" or a "double exclamation mark" before? data _null_; set &dset_in.; if i = _n_ then do i=1 to nvar; call ...
0
votes
2answers
21 views

Loop with i-1 doesn't find correct value

Task: Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not ...
0
votes
1answer
30 views

MATLAB - reading multiple dat files for loop

Hello everyone I'm trying to make a loop file to read several files, this is what I have done so far: anoini = 1980; anofin = 1981; mesini = 1; mesfin = 1; diai=1; diaf=1; nano = (anofin-anoini)+1;...
-3
votes
1answer
25 views

Averages in javascript [on hold]

I am looking to create a javascript prompt that will prompt a user for two values then output an average. I have tried doing this in a loop but I haven't been able to do it yet. Any advice? Regards
0
votes
0answers
21 views

Google Sheets Sending Email Twice

I have created a google apps script to automate emails based on a certain condition. It works, but has a major bug that I can't figure out. The bug is that it will send out two emails at the same ...
0
votes
3answers
39 views

Looping in kotlin in line

i have some trouble in using kotlin for looping i have json as like below : { idEvent: "584412", strEvent: "Huesca vs Girona", strHomeYellowCards: "28':Ezequiel Avila;34':Juan Nunez Aguilera;45':...
1
vote
2answers
31 views

Generate .click functions inside for loop

Inside my for loop that loops through 15 "box" objects, code below: for (var i = 0; i < boxesLength; i++) { I'm trying to generate these click events automatically, they used to be like this: (...
0
votes
2answers
22 views

JS/Jquery and firebase login page issues

I am trying to build a login page. After a user has logged in correctly I want to exit the index.html page and redirect to my portfolio.html page. firebase.auth().onAuthStateChanged(user => { ...
0
votes
3answers
36 views

How to create new column conditional on existing columns in pandas dataframe using for loop

I have a dataset of two columns and I want to create a third column that says whether the values of the first two columns are identical, and names the identical value for each row. Example data: ...
-1
votes
1answer
30 views

My simple Java pi calculator always seems to give infinity? [duplicate]

I am coding this simple pi calculator for my Java class as a part of us learning about basic loops and it seems like everything is OK except the values printed for pi is infinity when it should be 3....
1
vote
1answer
55 views

One line for loop to multiple lines python

I've got trouble reverting below one line loop to multiple lines loop. here is the original code: sequences = [[[item.strip() for item in itemset.split(",")] for itemset in sequence] for sequence in ...
1
vote
1answer
49 views

C/C++ bit array resolution transform algorithms

Anyone aware of any algorithms to up/down convert bit arrays? ie: when the resolution is 1/16: every 1 bit = 16 bits. (low resolution to high resolution) 1010 -> ...
0
votes
2answers
47 views

Nested loop with 'if' statements

I am trying to loop through an array of options, and check each option to see if it matches a different option within a different array. If the two options match, do one thing, if they don't match, do ...
0
votes
4answers
46 views

How can i compare and print an element from a 2D list in python?

I have this 2D list where the first element is the name of company the second is how much a senior developer gets salary and the third element is how many hours they work/week. brands = [["Microsoft",...
-2
votes
3answers
40 views

5.2 Eloquent Javascript - 3rd Edition

Relatively new at programming, looking for an explanation of a question in Chapter 5 of Eloquent Javascript. Your own loop Write a higher-order function loop that provides something like a for ...
0
votes
0answers
20 views

Unable to execute loop with conditions based on time in MATLAB

I was trying to execute a set of MATLAB commands. fault_test_data (after being transposed as per first line of command) is a 29736 x 9 double matrix. Its first column consists of months, and second ...
0
votes
1answer
23 views

create new column based on other column values after iterating through multiple lists

I have a dataframe that includes a column with multiple foods items. I want to create a new column with the food item type, which is stored in multiple lists. Here are my lists: fruits = ['apples',...
2
votes
5answers
56 views

How to iterate each number in array and sum them with the other numbers in the same array - JS

I'm trying to sum every number in the array with the next numbers and save all results: This is my example: var arr = [2, 3, -6, 2, -1, 6, 4]; I have to sum 2 + 3 and save it, then 2 + 3 - 6 save ...
0
votes
1answer
44 views

C# craps simulation

I have seen questions related to Craps, but they were related to python and Java. I hope someone familiar with C# can help me. The code below is meant to simulate the game of craps. The code mostly ...
1
vote
3answers
48 views

Limiting number of loops in a statement?

I have an assignment for my programming fundamentals class. In this, I have to accept invalid inputs a certain number of times (in this case, five) before the program terminates. The book doesn't seem ...
1
vote
2answers
40 views

How to write pairwise similarity to an file in R programming

I have a tab file: string.tab, which contain some think like below Entry String Dog cube;funny;smart Cat tiny;cube;black .... I also have an package Sim() to compute the similarity between two ...
0
votes
1answer
33 views

Extract a block of text between two strings, repeat process throughout document

I am using python to attempt to read a txt file and pull out multiple blocks of text between strings. Here is an example: something something something I dont want Select and then any length and ...
1
vote
2answers
38 views

Print each line of json in new .json file using Python

I have a json file; I need to remove the id key from the content, which I can do with my code. Now I want to print each line of the json file in a new file and use the name filed in my json for the ...
0
votes
2answers
25 views

Iterating over a list until 2 conditions are met

I have a list, and I want to sum all the numbers in that list ... except that if a 6 comes up - that is not counted and any number from that 6, until a next 7 comes up (also not counting the 7). A 7 ...
0
votes
2answers
77 views

How to execute an instruction when loop ends in C

how can I achieve that the instruction printf(" "); is triggered then the loop ends? I have to write a program for my course which replaces all tab and space with a single space. #include <...
0
votes
1answer
18 views

R find a folder under parent dir using loop

I have a parent folder and two level sub-directory, and I am trying to find the 3rd level folder under which level 2 folder, the structure is like this Parent folder --> level 1 Manager folder: Tom /...
3
votes
3answers
35 views

R-Loop through data frame and count values greater than a value and removing rows

I want to loop through a large dataframe counting in the first column how many values >0, removing those rows that were counted.... then moving on to column 2 counting the number of values>0 and ...
0
votes
1answer
12 views

Wordpress: Iterative Parent Page if Custom Field Contains Page ID

I am trying to display a list based on the page. The list is built based on data in an ACF custom field, which is in a serialized array. The list is for employees in a department. I am setting the ...
-2
votes
1answer
21 views

Python: Help to create a loop?

I have to do this function in a loop. I would like to pass x. x, which indicates how many times the loop should go through. It's about my data getting longer and longer: def get_data(x): ts = round(...
-1
votes
3answers
45 views

C# Game of craps using dice roll method

The code below is for a game of Craps. I am not sure if the logic of the code is correct. I want to test it, but when I run this code no output is given. It compiles and a blank screen is displayed ...
0
votes
1answer
17 views

Building a custom object in powershell (Add-Member)

Trying to build a custom object inside a For-EachObject loop. Here is the code $infouser = New-Object -TypeName psobject (Get-ChildItem -Path "\\$poste\C$\Users").Name | ForEach-Object { $...
0
votes
1answer
35 views

Make first observation the variable name

I currently have a data set with 37 variables. I read in the data with import excel but what should be the variable names were read in as the first observation. I want to use a loop to move the ...
0
votes
3answers
31 views

oracle out ref cursor to a loop

How to pass the 'values' of the output cursor o_cur to a further loop? CREATE OR REPLACE PROCEDURE dyn_cursor (o_cur OUT SYS_REFCURSOR) IS script VARCHAR2 (4000); BEGIN script := 'select ...
0
votes
1answer
24 views

for loops for removing row names

I have a series of data frames of the following format: Q1_output Q2_output all the way to: QN_output I would like to reset the row names to null for all data frames in such a list. Is there a ...
0
votes
1answer
31 views

Iterrating in DataFrame and writing down the index of the values where a condition is met

I have a data made of 20 rows and 2500 columns. Each column is a unique product and rows are time series, results of measurements. Therefore each product is measured 20 times and there are 2500 ...
0
votes
0answers
25 views

Lua Loop Dosn't preform all the actions inside itself (the setFillcolor() command specificly) (SOLVED)

The comments helped greatly and solved the problem. but if you know a way to slow down a loop i would love to know I am working on a game in Corona (with Lua) where the player colours in a plant and ...
0
votes
2answers
34 views

Problem with loop to add values from one dataframe and to another based on conditions

In R, I have two dataframes. The first is called d and looks like this: d <- structure(list(id = c(384923059L, 384923060L, 384923061L, 386269528L ), decimalLatitude = c(46.08, 48.73333, 46.35, 58....
0
votes
1answer
34 views

Why is my program shifting s and c by the wrong amount if I enter 5 into my program but not with any other letters or number?

This program is meant to ask you for a sentence and a number then it shifts the letters down the alphabet all by the inputted number and then lets you undo it by shift it by minus what you enter. For ...
0
votes
0answers
58 views

JavaScript Script for Exploring a Website?

I'm trying to write a script that extract a database from a website. The main page contains a table in which all lines contain a link to another page that contains the wanted database. So far my ...