72,074 questions
-1
votes
1
answer
63
views
Using list to find variables from data in rows
I am trying to find a combination where it will go through the data to find matched variables for any value from the list First_row is found, any value from the list Second_row and any value from the ...
0
votes
1
answer
147
views
Construct a simple loop to create new data frames in R [closed]
I have a number of data.frames, with names apple, banana, and coffee. I want to create, and then export, new dataframes in a for-loop corresponding to each one, call them apple_new, banana_new, and ...
-6
votes
1
answer
116
views
Using for loop to find a common value for every time another common value appears
import pandas as pd
a=1
b=2
c=3
for n in range(10, len(df)-1):
if df.loc[n].isin([a]).any() and df.loc[n].isin([b]).any() :
for x in range(0, ...
4
votes
3
answers
175
views
Why does my C code display the correct output, but with garbage characters added after?
The practice question I am working on reads as:
Read two strings, both of them do not contain white spaces (but may contain non-alphanumeric, such as ‘,’, ‘.’, ‘/’ ...).
Display the first string ...
-2
votes
1
answer
67
views
DO Error during String Replacement using Windows Batch Script
I obtained a batch script from Google AI for performing string replacement on the content of a list of text files in Windows. This is what I got--with a little tweaking, first. (Just testing at this ...
0
votes
4
answers
156
views
How to encapsulate a for clause?
This is more like an exercise.
I have several conditions that affect 2 nested for clauses:
for(...)//1st
{
for(...)//2nd
{
...
}
}
and since there are various possibilities (each one ...
1
vote
1
answer
57
views
Redshift : Opening multiple cursors from within the same client connection is not allowed
I have the following procedure written in redshift, which uses 2 for loops to get country code first and then years as per the country codes.
--Procedure : sp_for_loop_test
create or replace procedure ...
-3
votes
1
answer
90
views
trying to create a getPrincipal function [closed]
trying to create a function to get the principal amount for a loan using the for loop for the sum of present values
def presentValue(amount, num_months, interest):
return (amount)/(1 + interest)**...
0
votes
1
answer
113
views
for loop over value in ForM.forM definition for that value's own type
Background
As the Lean Reference's Instances for nested types example shows, in a function that implements a type class method for a certain type, one can already use the type class instance for that ...
6
votes
2
answers
164
views
How to use the raku operator 'ff'or 'fff' in a 'for lines()' loop
Given the input file:
----------------
A
----------------
information for A
on these lines
----------------
B
----------------
Something about B
on these lines
etc
I want to produce:
A: information ...
0
votes
0
answers
60
views
Redshift - SQL Error: Internal jdbc driver error
I am trying to use for loop within the stored procedure to retrieve the employee id and process further but getting an error:
Error: SQL Error: Internal jdbc driver error
Procedure:
create or replace ...
3
votes
4
answers
126
views
Creating a group by loop using either single or multiple variables from a list in R
I am trying to perform a loop which loops through a list of single or multiple variables then sums a column. I am essentially trying to paste in from a list into the group_by() function so that it ...
2
votes
1
answer
87
views
Wrap `jax.lax.fori_loop` to systematically override `upper<=lower` tracing behavior
This is a follow-up to a previous question about the jax.lax.fori_loop function, with a little bit of a challenge for you at the end.
As described in the documentation, the fori_loop is never executed ...
1
vote
1
answer
103
views
Windows batch file cuts off file extension in for statement
I noticed that some software I use, AutoDarkMode, doesn't randomize the first wallpaper it switches to, so I thought I'd write a batch file to do it by copying one wallpaper in the folder and renaming ...
2
votes
2
answers
116
views
`jax.lax.fori_loop` with equal `lower` and `upper` should produce no iteration, but body still executed
I have a code that uses a bunch of jax.lax.fori_loop. The documentation of fori_loop says that "setting upper <= lower will produce no iterations". So I was naively expecting the loop to ...
-1
votes
1
answer
129
views
My "for loop" doesn't work in Playwright.js [closed]
I need to choose опе book without a sale. On the page, I have 9 products, and some of them have the class hasDiscount.
I need to choose the first product without the class hasDiscount. But: I need to ...
0
votes
0
answers
37
views
How to use the same n8n For Loop for multiple nodes (LinkedIn + X/Twitter)?
I’m new to n8n and currently learning how to use a For Loop to generate social media posts with a delay between each iteration.
I’ve set it up successfully for the LinkedIn node — the loop runs and ...
-2
votes
2
answers
122
views
Palindrome function returning mirror of last few letters (C) [closed]
Source Code below.
Self-teaching myself this language after taking a c++ course.
I find the length of the string, then use the difference between that and the number of loop iterations to assign the ...
0
votes
0
answers
62
views
Why does this count_divisors() function return 0 instead of the divisor count? [duplicate]
I'm trying to solve Project Euler Problem 12 in C++, which is to find the first triangular number with over 500 divisors.
I am currently trying to write a function that counts the number of divisors ...
1
vote
1
answer
205
views
How to use a "Loop limit" symbol in a flowchart representing a simple R "for loop"
I know that a simple R "for" loop like the following:
n <- 20
for (i in 1:n) {
print(i)
}
can be represented by a flowchart like:
However, in any set of flowchart symbols there is the ...
-4
votes
3
answers
142
views
How does control flow work in nested loops in C? (Understanding execution order) [closed]
While practising nested loops in C, I wanted to understand how control flows between an outer loop and an inner loop. I understood that the inner loop runs for each iteration of the outer loop, but ...
0
votes
2
answers
147
views
How do I assign a value according to conditional statement that use dates from multiple columns [closed]
I am using a large dataset which contains patients with 5 different cancer types. Each patient can have one or more cancer diagnosis, identified in the n.cancers column. There are also columns for ...
-3
votes
1
answer
76
views
How to print the tuples in a more user-friendly way
The code:
#This is the second version of the marks analysis program
L = [] #This list will contain both marks and subject
S = []
M = []#This list will only contain marks, for calculation purpose
def ...
1
vote
2
answers
187
views
How do I filter my data with a looped "if" statement while retaining data from both current, past and an average of current + past loops?
I'm currently trying to filter a dataset containing audio data on bird species. The data looks like this:
head(audiomoth_sample)
id
park
park_abbr
am_no
sci_name
com_name
start_s
end_s
conf
date_time
...
2
votes
1
answer
73
views
Unable to use @for loop on array of custom objects. Receiving error
Using Angular V18. Attempting to use the @for loop to render multiple child components, but receiving error "Type 'InputSignal<LoopTile[]>' must have a 'Symbol.iterator' method that returns ...
3
votes
1
answer
76
views
Are there differences in how angular's @for and ngFor handle change detection?
I've used ngFor for many years now, but have been interested in transitioning over to the newer @for as it seems to make the code a little cleaner (in my opinion). However recently I just discovered ...
4
votes
1
answer
135
views
Different title in ggsave PNG when looping over plots
Saving a ggplots as PNG within a loop gives me a wrong plot title for one of the plots.
See reprex below, output corresponds to what I see in RStudio plot pane.
But then, my saved PNG via ggsave() has ...
0
votes
1
answer
58
views
JsonNode not reading correct Node value
I am trying to read XML into a JSONNode so I can pull values from it. For some reason the .get() function is reading the wrong Node. This is the XML I am trying to read:
<order>
<order_ID&...
0
votes
1
answer
49
views
My inventory is malfunctioning (in Godot)
I've been programming an inventory system. When I created the function to drag objects from one slot to another, I've been stuck even after some research. At first, objects are dragged, but the ...
-5
votes
1
answer
157
views
Sequence of dates is not the desired in the macro
I tried so many times to code with my own understanding, but the VBA code did not return correct outputs as I do manually.
The objective:
Return the 2 below outputs:
a beginning date and an end date
...
3
votes
1
answer
90
views
Problem with nested loop logic and indentation in python
I am trying to re-run a nested for loop within a while loop if the while condition is not met. If the condition is met then I want the inner loop to terminate and proceed to the next iteration of the ...
-2
votes
1
answer
181
views
will C++ ever have keyword such as "for_parallel"? [closed]
While learning about parallelism, I learned that C++ support parallelism through functions such as std::for_each, std::transform and execution policy. So if, for example, we want to divide elements of ...
3
votes
4
answers
206
views
Cartesian product for both keys and values of a dictionary?
I need to get the Cartesian product of a dictionary {str: Fraction} with itself, but currently need to "loop" through the dict twice, once for the keys and once for the values.
The ...
0
votes
1
answer
90
views
how to create uniform nested lists and convert them in to multi dimensional arrays?
i would like to create a nested list of arbitrary depth (containing numerical values specifically) with uniform arbitrary lengths at each level and then compress it to a NumPy array of minimum ...
2
votes
3
answers
110
views
Open-MP Parallel for (three-dimensional array)
We are working with the following code:
int i, j, k;
for (i = 2; i < n; i++){ // S1
for (j = 3; j < n - 3; j++){ // S2
for (k = 4; k < n - 4; k++){ // S3
A[...
0
votes
2
answers
99
views
What am I missing to create a loop that works?
I have multiple simple DFs with survey results (I've made up test data below that yields the same result). I'm trying to write a loop to select two of the seven columns so I don't have to write the ...
5
votes
2
answers
269
views
Why is Numba more efficient with 2D vs 1D version of this loop?
I'm using Python 3.12.11 with Numba 0.61.2 on Ubuntu 22.04.5 and AMD Ryzen 7 3800X CPU. This benchmark:
import numpy as np, timeit as ti, numba as nb
@nb.njit(fastmath=True)
def f1d(img, w):
fl = ...
2
votes
1
answer
146
views
Why is my string not printing to PowerShell in C on second function call?
I'm a beginner programmer learning C as a hobby. I just learned about accepting user input using scanf() and thought it would be a fun learning experience to make a small "game" that runs in ...
0
votes
2
answers
159
views
Nested for-loop alternative
I have a python code that calculates a function F(X), where both F and X are arrays of the same shape. F(X) uses another function called from a package that only accepts a scalar as an argument, but I ...
-4
votes
1
answer
110
views
Comparing for loops vs spread and concat for merging arrays in JavaScript — performance and best practices? [closed]
I'm learning JavaScript and practicing merging arrays. Here's one of the methods I wrote using two for loops:
const arr1 = [4, 5, 7, 9, 8];
const arr2 = [-1, -2, 0, 12];
const arr3 = [];
for (let i = ...
0
votes
1
answer
153
views
While loops are testing faster than for loops - should I use while loops instead of for loops?
I am using Nginx + Lua (OpenResty, LuaJIT), and I did some performance tests on various loops.
local ngx_log = ngx.log
-- https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#nginx-log-...
1
vote
0
answers
41
views
Track number of in-use vs. idle workers in Matlab with fmincon
I'm currently in Matlab doing a set of fixed point iterations using fmincon. I use parfor multithreading to do so. However, one of my iterations in the parfor loop goes particularly slow just because ...
1
vote
2
answers
59
views
How to create multiple contingency tables in R by using sjt.xtab
I use and like the sjt.xtab crosstab tool from the sjPlot package. Is there a way to create multiple crosstabs in one output file for a defined independent variable and multiple dependent variables?
...
2
votes
1
answer
75
views
In Python, how to find difference between a specific column in one dataframe and numeric columns of another dataframe?
I have two datasets/dataframes df1 and df2, I want to generate df3 by finding the difference between numeric columns of df2 and df1's column_X.
#### copy and paste below to generate df1 and df2
...
0
votes
0
answers
31
views
Automate QGIS v.kernel.rast across multiple nested folders with Python
I'm using QGIS 3.40.8 and need to automate kernel density calculations across a nested folder structure. I don't know Python - the code below was created by an LLM based on my QGIS log output from ...
6
votes
1
answer
347
views
How does `template for` iteration work in C++26? [duplicate]
I'm experimenting with the new C++ compile-time reflection features (as described in P2996R0) and I testing a simple enum_to_string() utility using template for:
template <typename E>
requires ...
0
votes
1
answer
94
views
Moving files into folders based on their file name [closed]
I have been trying to figure out how to use VBScript to process files in a folder based on their names, create a couple of subfolders, and place the different files into the corresponding subfolders ...
1
vote
2
answers
84
views
Simplest way to open/close multiple <dialog> pop-ups on the same page independently of one-another?
HTML
<dialog class="dialog">
<button class="close" autofocus>×</button>
<p>Some Content</p>
</dialog>
<button class="button open"&...
0
votes
1
answer
124
views
The FOR loop is not producing the correct output, even though there are no errors
The user has ten chances to guess a four-digit number. After each guess, the computer should print out the message that is included in the code below. I would like the code to list the numbers that ...
0
votes
0
answers
35
views
Why does "let" behave differently from "var" inside a for loop with "setTimeout"? [duplicate]
I’m trying to understand the difference in behavior between let and var inside a for loop, especially when used with setTimeout.
Here’s a simple example:
for (var i = 0; i < 3; i++) {
setTimeout((...