26,491 questions
3
votes
2
answers
54
views
I'm getting an 'index out of bounds' error using solve_ivp
I'm trying to find the outbreak time (when the number of zombies >= number of humans) as a function of the zombification rate gamma, using the following code:
arrOutbreakT = []
arrGamma = np....
-2
votes
2
answers
128
views
My while loop is looping despite reaching the break. It loops once then goes on with the rest as normal. I am at my wits end [closed]
it's not breaking and I don't know why
This is the problem section of the code. It is working fine, the try except is fine, and the check if not in range's break is working fine. But not the second ...
3
votes
1
answer
89
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 ...
1
vote
2
answers
82
views
Using sed -i within a loop
I'm reformatting a big file with sample metadata. I have a file (let's call it File2) with the group each sample belong to, with one id and pop per line. My idea was to while read over that file and ...
-9
votes
1
answer
145
views
Using the .find() function in a loop [closed]
I was trying to get the last word of the sentence using the .find() method in a loop.
My code:
sentence = "please write a program which keeps asking the user for words"
index = 0
substring = ...
0
votes
1
answer
152
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-...
-4
votes
4
answers
180
views
"break" function doesn't work correct within "while" cycle
Task: to make console to display a message "Happy birthday!". Number of messages equals the number which user inputs to console.
Condition: program should break the cycle, when number of ...
1
vote
2
answers
117
views
Why is n mod n = n, instead of 0 in for loop, but correctly 0 in while loop? [closed]
I have constructed a for loop that I though would given me a "circular" index that starts at some number (n) and cycles around again to that number through the series 0 to n, that is "...
2
votes
3
answers
156
views
Can someone help me understand this unexplained behaviour in C char arrays?
I have a function called escape that copies over a character array into a new one while replacing the \t and \n characters with raw characters \t and \n i.e single character '\n' becomes 2 characters '...
-1
votes
2
answers
96
views
Why is the "Continue" statement in Bash not correctly executed inside a "while" loop as part of a "&&" statement?
I face the following problem, which looks like a bug (or maybe am I the bug):
I have a loop:
#!/bin/bash
#
TARGET=/sd/REMOTE_BACKUP
LOGDIR=/sd
DEBUG=:
# Init daily information (reset on each run and ...
0
votes
6
answers
231
views
Trying to shift in a while loop
I need to create a program that can do this:
Input:
args2 one two three
Output:
You have entered 3 arguments:
#1: one
#2: two
#3: three
This is what I have so far:
#!/bin/bash
echo "You have ...
0
votes
2
answers
156
views
Why the while loop is not executing with strlen(sentence) - 1?
The code is supposed to reverse the words that have the length equal to longest word length from the phrase.
Input string: #Voi#da#bacu#la#info#
Expected output string: #Voi#da#ucab#la#ofni#
I ...
1
vote
1
answer
186
views
While loop interates a number of times equal to the amount of bytes in input
I am a novice to programming, and I'm doing it for fun. I encountered a strange bug I do not understand while trying to parse simple user input.
My problem is that when an invalid character is read (...
0
votes
0
answers
30
views
Shell scripting: effect of 'clear' command on conditional control structure
I don't know why, but only the '0' option works, unless the 'clear' command is removed or commented out. See the script:
NUMERO=-1
while [ $NUMERO -ne 0 ]; do
clear
echo "------ M E N U -...
0
votes
0
answers
59
views
Is it ok to suppress there warnings [duplicate]
I have code that has two warnings.
The code is from a commandline Expense manager project that uses a List to save and access expenses. Saving and retrieving the List is done via serialisation and ...
1
vote
2
answers
92
views
How to create a while loop with integer inputs in Python using a sentinel value that is not an integer
I was presented with this question as part of my Intro to Prog & Logic class.
Problem 5: Write a simple program that the user can enter any number of positive and negative integer values and ...
-6
votes
2
answers
69
views
Loop with 'for' [closed]
This is a Python 3 question for loops using 'for'
Why does the print(num-1) still execute at range 4? In my mind when range is 4 it should skip print(num-1) and go straight to else: print(num).
for ...
0
votes
0
answers
45
views
Xojo: Array gets modified when While loop ends?
I had this piece of code:
While match <> Nil
Var block As New Glyph
block.Abstract = match.SubExpressionString(1)
block.Noun = match.SubExpressionString(2)
block.Verb = match....
0
votes
1
answer
93
views
Moving result within PHP while loop up one line?
The following code is simple and works when trying to compare previous values from one column to the next. The only problem is that it is displayed one row below where I want. So the numbers do not ...
1
vote
3
answers
159
views
Switch inside while and break statement
Suppose I have a piece of C code
while(1)
{
switch(a){
case 1:
if(b==1)
break;//first break
break;//second break
}
}
...
0
votes
1
answer
97
views
Snowflake SQL - while loop inserting values to the table with statistics and aggregations
I'm trying to create a way of inserting aggregated data into a table by using a loop with a moving cursor. I want to count records in a 1h timeframe and compare it to the average number in ...
0
votes
0
answers
106
views
I want to fetch each values from my json file and evaluate in my application using loops
I have a JSON file which looks like this
[
{
Mem id:12345
DOB: 04041994
},
{
Mem id:5678
DOB: 05061987
}
]
I want to take each mem details and validate in my application using loops. ...
1
vote
1
answer
133
views
Run loop while writing to paramiko SFTP file is in progress
I'm writing a script that will transfer large amounts of data to an SFTP server, and I'd like to have some sort of terminal print-out during the long loading time for troubleshooting/debugging. I'm ...
0
votes
0
answers
33
views
Using TRADER package in RStudio, this stops me: Error in while ((!is.na(above[iil - 1, i])) & (iil > 1)) iil <- iil - : argument is of length zero
I am using TRADER package in RStudio in my dendrochronology project and this error keeps popping up after entering the function growthAveragingALL().
Error in while ((!is.na(above[iil - 1, i])) & (...
4
votes
4
answers
186
views
Why doesn't the condition of my while loop 'apply' to my print() statement? [closed]
Only started learning Python a few days ago. I followed freecodecamp's while loop word guessing game tutorial and wanted to add the statement, "Wrong answer!" after every wrong guess.
This ...