26,490 questions
-1
votes
0
answers
35
views
How to make while with empty body kotlin (fun used for condition) [closed]
Can anybody explain me how to make "while" with empty body look better?
I know that I can do this a different way, but I am really interested in the ways of implementing "while" ...
3
votes
2
answers
71
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....
-3
votes
1
answer
121
views
How do I only accept specific string input [closed]
I want to write a code that finds the derivative to any function and want to take a user input on what type of function they're inputting is. Essentially I tried to write a while loop that only accept ...
-2
votes
2
answers
132
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 ...
0
votes
2
answers
99
views
partclone print progress every nn seconds to a new line in bash
I have searched everywhere but could not find a solution hence posting here. Partclone prints the status / progress on the same line and it keeps updating this line, I want the progress to be ...
3
votes
1
answer
97
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 ...
3
votes
3
answers
220
views
While loop in C clipboard program doesn't work properly?
I want this program to first ask user to start or exit which works fine:
#include <stdio.h>
int main()
{
int ask;
char ask2;
char clip[100];
printf("1.start\n2.exit\n&...
1
vote
2
answers
88
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 ...
2
votes
1
answer
150
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 ...
-9
votes
1
answer
151
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
2
answers
167
views
C program won't skip second half of While statement [closed]
I have this homework program to calculate mpg. The -1 is the sentinel value which is supposed to skip the questions asking the user for gas and miles when inputted. At the moment, the program ...
0
votes
1
answer
160
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-...
0
votes
0
answers
83
views
ETA/Timer logic issues with indicatif
I've been building a promo-doro timer using the indicatif library, but I notice that the ETA provided by indicatif does not work properly when running the timer logic manually.
The timer always starts ...
-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 ...
3
votes
1
answer
96
views
Python While loop is executed, but then it fails to execute an if statement after it
I am working on a simple 2 player dice rolling game and have found a problem that i haven't been able to fix, after a While loop, it refuses to execute an if statement
def Main():
global player1_score,...
1
vote
2
answers
118
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 "...
-1
votes
2
answers
107
views
While statement not continuing when calling a function in python
While, "strong_beat.play()" is in the while loop, it stops running
*import simpleaudio, time, math
temp = 0
strong_beat = simpleaudio.WaveObject.from_wave_file('metronome2.wav')
while temp&...
2
votes
3
answers
166
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 '...
0
votes
2
answers
80
views
Different Variable in while loop [duplicate]
Is it possible to save a value on different variable in a while loop?
For example this is my code
category = [] #differs depending on the input of user
var1 = []
var2 = []
var3 = []
i = []
max_count =...
-1
votes
2
answers
100
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 ...
2
votes
1
answer
93
views
Having some trouble trying to verify credentials from get-credentials. Is there a better way?
I thought my script worked in test environment (it prompted me for credentials again and again when I mistyped, but accepted them after I typed them correctly). But when I tried to use it in ...
0
votes
6
answers
238
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
1
answer
112
views
Simple Bash script Nested while and for loops while reading from a text file
I have the following bash script which works fine but only goes through the for loop once!
#!/bin/bash
csv_file="regime.csv"
ratio=(0.2 0.4 0.6 0.8)
while IFS=',' read -r col1 col2 col3 ...
0
votes
2
answers
157
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 ...
0
votes
1
answer
85
views
How can i get a jquery function work in aPHP while loop
I'm having a bit of a challenge.
I have a table with input fields and some data that i fetch from the DB in a while loop.
Now I want to calculate the sum of input1 * input2(value=10) and show it in ...
1
vote
1
answer
187
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 (...
1
vote
0
answers
29
views
Python: Quitting a Game At Any Time [duplicate]
I'm creating a multiplication game and am suck on two things. I know they deal with break and continue use.
repeating the same question over again until it is right
providing an option to quit and ...
0
votes
1
answer
44
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
1
answer
69
views
For loop inside While loop not breaking - Matlab
Flag = 0;
while Flag == 0
for x = 1:10
if x == 3
Flag = 1;
end % end: if
end % end; for
end % end: while
Can anyone tell me why the while loop condition is not ...
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 ...
0
votes
3
answers
156
views
Complete the program to verify that a string contains a valid integer value. To be a valid integer the string can only contain digits
I'm currently taking a beginner programming course, and we are using Zybooks. I'm working on a participation activity where I am tasked with completing an existing program to verify that the string ...
1
vote
2
answers
100
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 ...
0
votes
1
answer
119
views
In Lua, is `repeat ... until condition` equivalent to `while true ... if condition break`?
In Lua, are these two snippets exactly equivalent?
repeat
...
until <condition>
while true do
...
if <condition> then break end
end
At first glance they seem ...
-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 ...
1
vote
5
answers
129
views
Bash Script While Loop from two files [closed]
Im trying to do the below:
file1:
x.x.x.5
x.x.x.6
file2:
router
switch
Trying to loop through both files to create two additional files each name in file2 as:
ping_router.sh
sudo /sbin/mtr -rn -c 30 -...
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....
-3
votes
1
answer
68
views
My while loop on JavaScript isn't re assigning a value back to its original variable
I am writing this JavaScript code using the while loop that asks a user for there age. I've written the code but it accepts me even after filling ages below 18. How shall I go about it?
I tried the ...
0
votes
1
answer
97
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 ...
2
votes
2
answers
83
views
How to read piped output produced in background subshell
I'm creating a script where multiple outputs from background processes are captured through while-read loop. However, it only works if I capture output directly to while loop. Trimmed down version of ...
1
vote
3
answers
177
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
}
}
...
-2
votes
1
answer
62
views
Increment arithmetic in TCL
I am trying to increment the output by 2 (every line increment by 2) while reading in a file.
Here is my code:
Input.txt:
green
yellow
grey
purple
SCRIPT:
set infile [open "input.txt" r]
...
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 ...
1
vote
1
answer
59
views
Bash while read loop messes variables definition [duplicate]
I have a csv file test_list containing only lines of text:
> cat $test_list
test_name_1
test_name_2
> typeset -p test_list
declare -- test_list="test_list.csv"
I want to test that ...
0
votes
0
answers
119
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. ...
3
votes
3
answers
170
views
Issue with getchar() Skipping Input in a C Program
A number guessing C program; After the 4th iteration which prompts “well, is it 5 then?”, the character \n (enter) still remains in the buffer which then gets read by the first getchar() in the while ...
1
vote
1
answer
149
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 ...
1
vote
2
answers
128
views
Why does sed in bash remove leading and trailing whitespaces from a string? [closed]
This is a MRE of a larger bash script, that replaces characters in filenames based on a list of files and a character map. Instead of a file list from a file I'm reading in two "files" from ...
0
votes
0
answers
36
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])) & (...
2
votes
2
answers
62
views
micropython on picoboard while loop not working
from picozero import pico_led, Button, LED, Buzzer
from time import sleep
led16 = LED(16)
button12 = Button(12, pull_up = False)
button15 = Button(15, pull_up = False)
buzzer14 = Buzzer(14)
global ...
4
votes
4
answers
195
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 ...