while-loop

Bash while loop syntax error in do

[亡魂溺海] 提交于 2019-12-12 05:08:19
问题 I´m trying do do a simple counter: max=100 count=1 while [[ $count -le $max]] do echo "$count" ((count++)) done This gives me a syntax error in conditional expression near do. What´s my issue? (probably something obvious) The idea is then to raise the max from 100 to 200 and so forth in a superior loop so I will get a new file to manipulate with a python program 100 lines each time, but that´s irrelevant here. 回答1: Your mistake is that it need one more space in [[ $count -le 100]] max=100

Multiply recursiverly in r

自作多情 提交于 2019-12-12 05:06:43
问题 Having the following matrix and vector. x<-matrix(c(1,4,7, 2,5,8, 3,6,9), nrow = 3) w <- c(1,1,1) res <- c() What is the best way to multiply recursiverly till obtain a desire sum of the results as exemplified: res[1]<-w %*%x[1,] res[2]<-w %*%x[2,] res[3]<-w %*%x[3,] res[4]<-w %*%x[1,] res[5]<-w %*%x[2,] sum(res)>1000 #Multiply recursiverly till the sum of the results sum(res) goes further than 1000. 回答1: Here is how to do it recursively : f <- function(x, w, res){ if (sum(res)>1000) return

Array items are deleted after exiting 'while' loop?

帅比萌擦擦* 提交于 2019-12-12 04:59:28
问题 I have a 'while' loop that is checking Firebase for some prices on a menu. For each item, it goes to a specific ref URL and grabs that dish's price, then commits it's value to an array to be displayed on a table. var i = 0 while i < self.itemNames.count { itemNameRef.childByAppendingPath("\(self.itemNames[i])/itemPrice").observeEventType(.Value, withBlock: { snapshot in self.itemPrices.append(snapshot.value as! String) }) i++ } Thing is, it seems to clear my entire array once it exits the

cin fails to stop while loop

我的梦境 提交于 2019-12-12 04:44:18
问题 I was wondering if you guys could explain to me why this loop doesn't loop if I enter 'r' in for the value of 'value'. double value std::cout << "Please enter a real number: "; std::cin >> value; while (!isdigit(value)) { std::cout << "Sorry, but only numbers are valid.\nPlease enter a real number: "; std::cin >> value; } Thank you very much. 回答1: You shouldn't be using isdigit() here because that's for testing whether a single char type is an ASCII digit. If you're expecting the user to

Loop in PHP not working

对着背影说爱祢 提交于 2019-12-12 04:43:23
问题 $qPhysician = mysql_query("SELECT * FROM physicians"); $num = mysql_num_rows($qPhysician); $i=0; while($i < $num) { "<tr>"; "<td>" . mysql_result($qPhysician,$i,"lastName") . "</td>"; "<td>" . mysql_result($qPhysician,$i,"firstName") . "</td>"; "</tr>"; $i++; } I get blank result. If I echo $num , I get "19" which is the number of rows in my DB. If I echo $rowPhysician['lastName'] just to test out if I get records, I get at least 1 record of last name. I don't know if there is something wrong

Concatenating string names of variables matlabfile in R

烈酒焚心 提交于 2019-12-12 04:36:25
问题 I have matlab files with an integer in each name of my variables inside (except the first one). I want to loop to concatenate the name of the integers. There is my code: library('R.matlab') mat <- readMat('SeriesContPJM.mat') #str(mat) #typeof(mat) #mat[[1]] write.csv(mat$vol.PJM$data[[4]][[1]], "PJM.csv") i = 2 while (i < 7) { write.csv(get(paste("mat$vol.PJM", as.character(i), "$data[[4]][[1]]", sep = "")), paste(paste("PJM", as.character(i), sep="_"), "csv", sep =".")) i = i + 1 } I have

Repeat Result for num rows in php [duplicate]

寵の児 提交于 2019-12-12 04:14:40
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: i can’t make num rows inside while looping i try allot of to make num rows in while looping to get number of rows for another tables $select_sub_cat = mysql_query("SELECT * FROM sub_cat WHERE ct_id='".$row_main['id']."' LIMIT 8 "); while($row_sub = mysql_fetch_array($select_sub_cat)) { $select_num_sub = mysql_query("SELECT * FROM market WHERE sub_cat='".$row_sub['id']."' "); while($row_num_sub = mysql_fetch

While loop with if/else statement in Python

偶尔善良 提交于 2019-12-12 04:10:00
问题 So I am still in the process of learning Python and I am having difficultly with while loops. I have a sample of code below that includes while loop and if and else statements. What I want it to do is print 'Less than 2' and 'Greater than 4' which it does, but it keeps running. It does not print it just once each which is what I would want it to do. Any help would be greatly appreciated! counter = 1 while (counter < 5): count = counter if count < 2: counter = counter + 1 else: print('Less

Jmeter - Loop counter in while loop not resetting on exit

只谈情不闲聊 提交于 2019-12-12 04:09:03
问题 I have the following code construct in Jmeter: Test Plan - CSV Data config (reading in test reacords) - Execution Thread - - Do While (contains condition Counter < 5) - - - Counter element (set to start at 1, increment by 1) - - - Http request sending test record to api The problem I am getting is that the Counter is not resetting after each test record is sent through, so the first record through works fine (5 iterations), the second stops at the first iteration. I've tried: 1) Set counter

Simple Loops and String Length in C

跟風遠走 提交于 2019-12-12 04:05:45
问题 I'm pretty new to C. Writing in Visual Studio 2015, I'm trying to safely prompt a user for a string by using fgets. I want to use fgets to get the string, check if the string is too long, and reprompt the user if it is until they enter a good string. Here is my code /* * Nick Gilbert * COS317 Lab 2 Task 2 */ #include "stdafx.h" int main() { char str[10]; int isValid = 0; while (isValid == 0) { printf("Please enter a password: "); fgets(str, 10, stdin); if (strlen(str) == 9 && str[8] != '\n')