while-loop

The variable inside while loop is not remembered. Mysql bash script auto_increment

妖精的绣舞 提交于 2019-12-11 04:46:11
问题 I've working on this script for quite some time. But I started to see some errors when I tried to add a variable ($EMAIL_MSG) to store some strings of text to later be emailed. It seems that the variable inside while loop is not remembered. (A variable modified inside a while loop is not remembered) Here is part of the script: #!/bin/bash # # This is bash script checks when auto_increment column is reaching its limit # To run Script $ ./auto_increment_check.sh [username] [password] MYSQL_USER

Perl: Pulling pairs of values from an array

♀尐吖头ヾ 提交于 2019-12-11 04:45:47
问题 Consider #!/usr/bin/perl use strict; use warnings; while(<DATA>) { my($t1,$t2,$value); ($t1,$t2)=qw(A P); $value = $1 if /^$t1.*$t2=(.)/; ($t1,$t2)=qw(B Q); $value = $1 if /^$t1.*$t2=(.)/; ($t1,$t2)=qw(C R); $value = $1 if /^$t1.*$t2=(.)/; print "$value\n"; } __DATA__ A P=1 Q=2 R=3 B P=8 Q=2 R=7 C Q=2 P=1 R=3 I'd like to replace the repetition with an elegant loop over pairs of $t1,$t2 values stored in an array (or other structure) like one of my @pairs = qw (A,P B,Q C,R); my @pairs = qw (A P

While loop not counting correctly [duplicate]

夙愿已清 提交于 2019-12-11 04:45:28
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed last year . I've been learning programming in python for the last two weeks and it's going great so far. But now I'm stuck and can't seem to find an answer. I found a really weird behaviour of a while loop, I just can't wrap my head around. x=0 step_size=0.2 while x<2: print x x+=step_size This code prints: 0 0.2 0.4 ... 1.8 2.0 2.0 should not be printed, right? When x becomes 2.0 the statement "x<2"

Javascript callback within a while loop does not work?

六眼飞鱼酱① 提交于 2019-12-11 04:44:23
问题 I'm trying to make an event driven while loop in javascript. Essentially it iterates through an array of values and makes a query during each iteration. Then, based on the result of the query it should either keep looping or stop and do something. I realize that you can't have callbacks in a while loop so I'm confused on how to even implement such a thing. Nested functions repeat themselves and that's not ideal. my loop code: var done = false; while(!done){ bridgeCheckRooms(send,function

Counting data points within limits, and applying buffer to isolated points [data analysis]

≡放荡痞女 提交于 2019-12-11 04:40:34
问题 I am stuck trying to solve this problem: I have a set of data points, that correspond to a set of time values. i.e. values =[1,2,3,4,5,6,7,8,4] times = [0.1,0.2,0.3,0.4]... and so on, it's a sample rate of 10hz. I need to find the time spent between two limits. so for example if my limits are 3 and 5 inclusive then 3,4,5,4 are in my limits. if I calculate the time as number of ( points -1) /sample rate , or the start time and end time of the grouping, I will miss out the isolated data point

How to loop scanf_s() until success?

夙愿已清 提交于 2019-12-11 04:38:15
问题 #include <stdio.h> int main(){ float x,y; printf("Enter 2 numbers: \n"); scanf_s("%f %f", &x, &y); if (getchar() == '\n') { printf("Division: %f\n", x / y); printf("Product: %f\n", x * y); printf("Sum: %f\n", x + y); printf("Difference: %f\n", x - y); } else { printf("no Float-Value!"); } getchar(); return 0; } we need to get a loop in so if we enter the wrong format the program should ask again to enter two numbers 回答1: The best way of checking the validity of the input is to check the

Single line while loop updating array

非 Y 不嫁゛ 提交于 2019-12-11 04:29:32
问题 I am trying to build a while loop that updates the values in an array but I keep getting a command not found error. i=1 bool=true declare -a LFT declare -a RGT while read -r line; do ${LFT[$i]}=${line:0:1}; ${RGT[$i]}=$(wc -l < temp$i.txt); if [ ${LFT[$i]} -ne ${RGT[$i]} ]; then $bool=false; fi; ((i=i+1)); done<output2.txt The file I am reading from contains a single digit on each line, and I want to fill the array LFT with each entry being the digit. The array RGT should be filled with the

Can't stop while loop

╄→гoц情女王★ 提交于 2019-12-11 04:08:23
问题 In this game that I created I ran into a problem. It all works great except that if you fail for some reason the game just restarts and that's not what I want. I want to display what I have it set to display and then break the loop, for some reason the break; isn't working. Code: import java.util.Scanner; import java.util.Random; public class GuessingGame1_3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Random rand = new Random(); System.out.print("Pick a

VBA Go to the next filtered cell

大城市里の小女人 提交于 2019-12-11 04:07:56
问题 I am currently using the following code: Sub SendEmail() Dim objOutlook As Object Dim objMail As Object Dim RowsCount As Integer Dim Index As Integer Dim Recipients As String Dim Category As String Dim CellReference As Integer Set objOutlook = CreateObject("Outlook.Application") Set objMail = objOutlook.CreateItem(0) If ActiveSheet.FilterMode = True Then RowsCount = ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1 ElseIf ActiveSheet.FilterMode = False

Using text as condition in a while loop

强颜欢笑 提交于 2019-12-11 03:24:29
问题 Im having some trouble with using text as an condition for a while loop, currently the basic coding is: result=struct('val','yes'); while result.val=='yes' result.val=input('more digits?'); end So as you see, what Im trying to do is keeping the loop going as long as the user types in 'yes'. But thats one of the probelmes I am having; Is there a way to get rid of the need to write the ''(e.g yes instead of 'yes')? Secondly, when I run the code it gives me the error message "Error using ==