while-loop

Bash loop control while if else with a return

℡╲_俬逩灬. 提交于 2020-01-06 14:42:46
问题 I need to return a true or false if I find a value within a file. I parse the file and if the value is located once which is enough, I want to break and return a true else return false. On top of it I need to pass the file into this check function. I'm trying to only use bash. is_file_contains_VAR(){ VARFILENAME=$1 while read LINE do if echo "$LINE" | grep -q "$VAR"; then break return 0 else return 1 fi done < $VARFILENAME } 回答1: grep -q already does what you want: it will abort as soon as it

Catching multiple errors in loop SQL query

会有一股神秘感。 提交于 2020-01-06 12:14:01
问题 I have the below insert query which selects records from the OriginalData table where everything is of datatype nvarchar(max) and inserts it into the temp table which has specific column definitions i.e MainAccount is of type INT . I am doing a row by row insert because if there is a record in OriginalData table where the MainAccount value is 'Test' the it will obviously cause a conversion error and the insert will fail. The begin try block is used to update the table with the error. However

Catching multiple errors in loop SQL query

纵然是瞬间 提交于 2020-01-06 12:13:16
问题 I have the below insert query which selects records from the OriginalData table where everything is of datatype nvarchar(max) and inserts it into the temp table which has specific column definitions i.e MainAccount is of type INT . I am doing a row by row insert because if there is a record in OriginalData table where the MainAccount value is 'Test' the it will obviously cause a conversion error and the insert will fail. The begin try block is used to update the table with the error. However

While loop fails when socket reading input in java

依然范特西╮ 提交于 2020-01-06 10:38:50
问题 so I am having an issue with reading input from a client. It works completely fine whenever I am using my if statements without the while statements wrapped around it in the server class. Could anybody point me to why this may be failing? Server class: import java.io.*; import java.net.*; public class Server { public static void main(String[] args) throws Exception { Server myServer = new Server(); myServer.run(); } public void run() throws Exception { //Initializes the port the serverSocket

My browser goes unresponsive when I try to execute this JS

微笑、不失礼 提交于 2020-01-06 09:56:28
问题 I use this code to add or remove certain nodes from a page I have on my site: function nextChild() { var elem = document.getElementById('formtbody'); var a = 0; var b = elem.childNodes[a]; var node = b.style.display; var lastnode = 0; while (node !== "none") { (lastnode++); (a++); } (lastnode++); var c = lastnode; var therightnode = elem.childNodes[c]; return therightnode; } function addRemoveClass(option) { var elem = document.getElementById('formtbody'); if (option === "add") { nextChild()

Logical Error in if else statement in java

こ雲淡風輕ζ 提交于 2020-01-06 09:03:05
问题 My code: import org.ujmp.core.Matrix; import org.ujmp.core.SparseMatrix; public class part { public static void main(String args[]) throws Exception{ Matrix Bigomega=Matrix.Factory.zeros(6,6); Matrix omega = SparseMatrix.Factory.zeros(6, 6); int []timea={1,2,3,4,5,6}; int [] timeb={3}; int k1=0,k2=0; while (k1 < timea.length && k2 < timeb.length ) { if (timea[k1] < timeb[k2]) { omega.setAsInt(1, k1, k1); omega.setAsInt(-1, k1, k1 + 1); omega.setAsInt(-1, k1 + 1, k1); omega.setAsInt(1, k1 + 1,

Getting rid of excess while statement

我只是一个虾纸丫 提交于 2020-01-06 08:26:12
问题 Could anybody have a look at this snippet of code and and tell me if there is a way to amalgamate the two while statements into one? public static void main(String[] args) throws IOException { BufferedReader fileInput; fileInput = new BufferedReader(new FileReader("information.txt")); int countOfClients = 0; while (fileInput.ready()) { fileInput.readLine(); countOfClients ++; } int totalClients = countOfClients ; Client[] clientDetails = new Client[totalClients]; int clientNumber = 0; while

PHP while loop split into two

天涯浪子 提交于 2020-01-06 08:25:11
问题 I'm running a while loop which is taking rows from mySQL and echo'ing them out. Pretty standard. However, there needs to be different HTML markup for the first item, next two items, then it continues as normal into the while loop. Currently, my while loop looking something like this: while( ( $row = mysql_fetch_object( $result ) ) !== false ) { // Places ad based of predefined variable frequency if ($ad == $adFrequency){ echo '<div class="one-advertisement-article clearfix">'; echo '<div

true as a condition in a javascript while loop [duplicate]

落爺英雄遲暮 提交于 2020-01-06 07:26:30
问题 This question already has answers here : JavaScript Infinitely Looping slideshow with delays? (10 answers) Closed last year . I was wondering why this code crash my browser: while (true) { $('.selector') .animate({ 'bottom': '30px' }, 500) .animate({ 'bottom' : '20px' }, 500); } and this other code works (without true as a condition) var a = 0; while (a < 1000) { $('.selector') .animate({ 'bottom': '30px' }, 500) .animate({ 'bottom' : '20px' }, 500); a++; } If i would dare to answer the

input sequential numbers without specific end in a data frame's column in r

核能气质少年 提交于 2020-01-06 07:09:12
问题 I would like to give a sequence of numbers to a new column to a data frame. But this sequence will repeat several times based on a value in another column. (i.e It starts from 1 until that specific value will be changed to other value). My problem is how to define the ending point for each sequence in r. A part of my data frame with the column "V2" which I intend to add: V1 V2(new added column with sequential numbers) 12 1 12 2 12 3 12 4 12 5 13 1 13 2 13 3 13 4 13 5 13 6 14 1 14 2 14 3 14 4