while-loop

function that iterates and assigns based on value in R

大憨熊 提交于 2019-12-02 08:23:57
问题 I'm looking to write a function that iterates through a list of accounts each with a value associated, and assign that account with one of the names in a list of names. The list of names will have values associated and I would like the assigned name to be the one with the least value. name totalvalue Jeff 54 Christy 43 Matt 29 Jessica 19 accounts value name acc1 8 acc2 7 acc3 7 acc4 7 acc5 6 acc6 6 acc7 5 acc8 3 What I would like is to iterate through the accounts list and look at the names

while loop not ending when required

早过忘川 提交于 2019-12-02 08:19:35
So some background information, I'm new to programming and am still learning, so I apologize for my trivial error making. I am making my own text based game just to further practice etc. Here is the link to everything on dropbox for more context: https://www.dropbox.com/sh/uxy7vafzt3fwikf/B-FQ3VXfsR I am currently trying to implement the combat system for my game, and I am running into the issue of the combat sequence not ending when required. The 'combat sequence' is a while loop as follows: public void startCombat() { inCombat = true; while(inCombat != false)// && herohealth > 0 &&

Multiple conditions in a while loop

霸气de小男生 提交于 2019-12-02 08:03:32
import java.util.Calendar; import java.util.GregorianCalendar; public class CountingSundays { public static void main(String args[]) { Calendar cal = new GregorianCalendar(1901, 00, 01); // month set to 0for jan , 1= feb etc while((cal.get(Calendar.YEAR) != 2001) && (cal.get(Calendar.MONTH) != 0) && cal.get(Calendar.DAY_OF_MONTH) != 1) { // while not 1/1/2001 System.out.print(cal.get(Calendar.MONTH)); // cal.add(Calendar.DAY_OF_MONTH, 1); } } } Im trying to iterate through the while loop by adding on a day at a time but it wont even access the while loop the first time. Are the conditions in

How do I fill an array inside a while loop and get new scope each iteration?

China☆狼群 提交于 2019-12-02 07:51:15
问题 The problem is that I get only the last value comming from the Table. I think its because I am building the array while referencing its values to the same object, and it keeps changing. I know while loop doesnt create a new scope for each iteration which IS the problem. What's the best way to get a new scope for each iteration? Code: $namesArray= array(); while ($row=mysql_fetch_array($result)) { $nameAndCode->code = $row['country_code2']; $nameAndCode->name = $row['country_name']; array_push

Getting infinite loop in fibonacci series in Python

偶尔善良 提交于 2019-12-02 07:25:37
#Program to print fibonacci until a range. print "Fibonacci Series" print "Enter a range" range = raw_input() first=1 second =1 print first print ", " print second print ", " third = 0 while(third < range): third=first+second print third print ", " first = second second = third #End of program Here, the program asks user for a range and prints the series upto the range. But, m getting the series of infinite loop. Can anyone help me? range = raw_input() sets range to be a string , e.g. it is assigning range = '5' rather than range = 5 . The comparison third < range will therefore always be True

bash script stops execution in while loop - why?

与世无争的帅哥 提交于 2019-12-02 07:24:26
I have this bash script for converting .mp4 video to .mp3 audio. It runs, but does the loop only once, though there are more mp4 files in /home/myname/mp4dir. The script converts the first .mp4 file it finds to .mp3, unless there is already an .mp3 file. This should be done in a loop, but after the first call to ffmpeg the script stops. Why? #!/bin/bash find /home/myname/mp4dir -name "*.mp4" | while read f do fOut=`echo $f | sed s/mp4/mp3/` echo "convert $f => $fOut" if ! test -f $fOut then ffmpeg -i $f -vn -f mp3 $fOut fi done From the comments we got that there actually are input files you

tkinter root.mainloop with While True loop

左心房为你撑大大i 提交于 2019-12-02 06:34:15
I am using tkinter to display some labels based on voltages I am reading. However, it stops executing after one read. I have found that it is due to root.mainloop(). But I am not able to fix it. I have included my code. The root.mainloop() is located right at the end of the while True. from Tkinter import * import spidev import time import os import RPi.GPIO as GPIO import numpy GPIO.cleanup() GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.setup(11, GPIO.OUT) GPIO.setup(13, GPIO.OUT) GPIO.setup(15, GPIO.OUT) GPIO.setup(12, GPIO.OUT) adcvolt = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] batvolt = [0

loop for file location until file exists in bash

天涯浪子 提交于 2019-12-02 06:17:51
问题 I have created this function: function promptFile() { while true; do read -p "Please provide a full path [q to quit]: " file if [ $file == q ]; then echo "Exiting.." return 1 fi if [ ! -f $file ]; then echo "File does not exist, please try again" else echo $file break fi done } To prompt a user for file location, ask again if file does not exist, and save the output to a variable if it does, the function is called: tempLoc=$(promptFile) if [ !tempLoc ]; then fileLocation=$tempLoc fi

PHP array into Javascript Array

有些话、适合烂在心里 提交于 2019-12-02 05:45:32
Afternoon all. The code below works perfectly, however, I need to pull each row of the php sql array out and into the script var. Any ideas on how to write a while loop that could do this? Thanks for any help var enableDays = ["<?php echo mysql_result($result, 0, 'date'); ?>"]; enableDays.push("<?php echo mysql_result($result, 1, 'date'); ?>"); Additional Code:: $rows = array(); while ($row = mysql_fetch_assoc($result)) { $rows[] = $row; } var enableDays = [<?php echo json_encode($rows); ?>]; console.log(enableDays[1]); You can get the rows using mysqli_fetch_assoc and then encode it to JSON:

scanf check in while loop to restrict integer input

偶尔善良 提交于 2019-12-02 05:34:42
问题 I am writing a code asking the user to input 10 integers, which are then fed to him backwards. I would like to create a "scanf check" to restrict character input. The while loop works insofar that it doesn't accept char, but it skips a integer input. int main() { int i = 0, number[10] = {0}; char buf[128] = {0}; for (i = 0; i < 10; i++) { printf("Please input number %d : ", i+1); while(scanf("%d", &number[i]) != 1) { scanf("%s", &buf); printf("Sorry, [%s] is not a number. Please input number