I believe you are incorrectly referencing to num instead of line which is the counter variable in your for loops, you either need to use num as the counter variable, or use line in the if condition. def countGasGuzzlers(list1, list2): total = 0 CCount = 0 HCount = 0 for...

You're referring to params.term as an existing array, which is why you're getting an error. Try this instead... params["term" + index] = .... That will create a property for each index instead. You can either access it with params["term1"] or... params.term1 ...

Change double average = sum/numbers; to double average = (double)sum/numbers; to force floating point division. Otherwise, int division (which is the operation that takes place when dividing two variables of int type) will give you 2 when dividing 8/3 (as you do in your example)....

simply iterate from 1 to the maximum number of offices n and add number of required plates to total. for 1 to 9 you need 1 plate, for 10 to 99 you need 2 and so on. we implement this by using limit and step. limit indicates when we need...

Your test variable is a three-dimensional variable, so when you do test2 = test(:,1); and then test2(:) <VaR_Calib_EVT/100 it's not the same as in your second example when you do test(:,i)<(VaR_Calib_EVT(:,i)/100) To replicate the results of your first example you could explicitly do the test2 assignment inside the loop, which...

There are two issues here. First, you need to discard new lines on your scanf. See here for details. Second the || operator is going to cause the whole statement to evaluate to true no matter if the user has entered Y or y. Try switching to an && operator...

This is effectively the same as the answer from Stephen Kennedy, but I sometimes like this syntax. Usually for more complicated things, but still: foreach (var item in from l in list1 where l == eCode select l) { // Do something with each item } ...

This line: public static string [] starGenerated = new string[numberOfForbiddenWords]; ... is executed when the class is initialized. That will happen while numberOfForbiddenWords is still 0, i.e. long before this line is executed: numberOfForbiddenWords = int.Parse(Console.ReadLine()); So when you call StarGenerator, unless numberOfForbiddenWords is still 0, you're going to be...

If you want to get the matrices to be displayed in each column, that's going to be ugly. If I'm interpreting your request correctly, you are concatenating row vectors so that they appear as a single row. That's gonna look pretty bad. What I would suggest you do is split...

There are three different options you have to choose from here, I will explain each one: Option 1 - break while first_draw == second_draw: first_draw = random.choice(card_values) + random.choice(card_classes) second_draw = random.choice(card_values) + random.choice(card_classes) break break will end the innermost loop. In this case, the loop will only run once....

There is no redo keyword for going back to the start of a loop, but there's no reason you couldn't do it with goto. (Oh I feel so dirty recommending goto...) int tries = 0; for(int i=0; i<10; ++i) { loop_start: bool ok = ((i+tries)%3==0); if(ok) { ++tries; goto loop_start;...

zip the lists and use a for loop: def downloadData(n,i,d): for name, id, data in zip(n,i,d): URL = "http://www.website.com/data/{}".format(name) #downloads the file from the website. The last part of the URL is the name r = requests.get(URL) with open("data/{}_{}_{}.csv".format(name, id, data), "wb") as code: #create the file in the format...

Use a do while loop to enclose your code and set the condition to what you want. #include <iostream> #include <string> #include <fstream> using namespace std; int main() { int flag=1; do { //your code that needs to be repeated //when you need to exit set flag=0 } while(flag); }...

You are using same variable (i) for both loops, and in the inner loop the condition of exit is i being 0 or negative, but the only change in this variable in the inner loop is i=i/10 which usually gives unexpected results when using with int. Also, the i will...

The problem arises from you mixture of subsetting types here: df$target[which(df$snakes=='a'),] Once you use $ the output is no longer a data.frame, and the two parameter [ subsetting is no longer valid. You are better off compacting it to: sum(df[df$snakes=="a","target"]) [1] 23 As for your model, you can just create...

the problem is when mouse-event fire value of i have value 6 or last value of for-loop for (i = 0; i < 6; i++){} you can create a jlable class and give a instance variable like lableindex so when mouse-event occurs you first get the lable index and then...

I'd wrap each textarea + word count (eg. in a div), and in the keyup event find the other child tag based on the shared parent element. This example just grabs the immediate parent but you could do it based on a common ancestor or its class name. eg. http://jsfiddle.net/mzqo2ruk/...

The fault is caused because the mouse interrupt 33h function AX=0003h returns the mouse position in CX and DX. This overwrites your "counter" in register CX. It is always a dangerous game to keep values in registers throughout a program. Better to have a memory variable location. You could also...

I am posting this answer to my own question, as per the comments received. It is not possible to make a timer because: The time that an iteration will take is unpredictable, this depends not only on the CPU used, but you need to take into account power management, the...

You have to call DirectoryStream<Path> files = Files.newDirectoryStream(dir); each time you iterate over the files. Pls check this question... java.lang.IllegalStateException: Iterator already obtained...

If the columns are delimited with tabs then you can do: role='Role A' number=$(awk -v role="$role" -F '\t' '$2==role {print $1}' role_info.txt) If it's just spaces, try instead: role='Role A' number=$(grep "$role" role_info.txt | cut -d' ' -f1) Either way, you can then check if a match was found with:...

You create new TD for each member. The nested foreach has to be: <td> @foreach($user as $mem) {{ $mem->name }}<br> @endforeach </td> The result will be: <td> Name 1<br> Name 2<br> Name 3<br> </td> I don't know the template engine you used, add inside a loop condition and don't put...

You are causing undefined behavior in scanf("%s", &c); because "%s" specifier adds a terminating nul byte to the target which is a single char. Instead you can try if (scanf(" %c", &c) != 1) handleErrorPlease(); the space before the "%c" is intentional, it will eat any white space character left...

There is no issue with the #define, there is one issue with the conditional statement in the for loop. I believe, you'er overlooking the <= operator. You need to have only < operator. Change for(i=0;i<=rows;++i) to for(i=0;i<rows;++i) That said, the recommended signature of main() is int main(void)....

The i++ is using post increment, so the value of the expression i++ is what the value was in the variable i before the increment. This code: if(sortedLetters[i] !== sortedLetters[i++]) return true; does the same thing as: if(sortedLetters[i] !== sortedLetters[i]) return true; i = i + 1; As x !==...

Yes, it's possible, and it works fine. for (i=-5; i<=5; i++) { ... } is the same thing as i=-5; while (i<=5) { ... } continue { i++ } The point is that any expression is allowed inside the for's first part....

You are indexing your lists with a non-int type index: for count in list_kp2_ok: for count1 in list_kp2_2_ok: if list_kp2_ok[count]==list_kp2_2_ok[count1]: So a quick fix for that is to do it this way: for coord1 in list_kp2_ok: for coord2 in list_kp2_2_ok: if coord1==coord2: You can even do the whole coding in...

If you're "trying to allocate an array 64 bytes in size", you may consider uint8_t Buffer[64]; instead of uint8_t *Buffer[64]; (the latter is an array of 64 pointers to byte) After doing this, you will have no need in malloc as your structure with a 64 bytes array inside is...

Simple answer, you don't. Because your function is called through timeout, it's not in the same context anymore and 'this' will not refer to the same object anymore. You can do this: loopThroughSplittedTextNotWorking: function() { // delete this var locationInString = 0; var that = this; function delayedOutput() { document.getElementById('output').innerHTML...

To give to each button a different id you can do this way: <?php $i = 1; foreach($queryResult as $res) { ?> // output all table columns <form onsubmit="return javascriptFunction(); " method="post"> <button id="element-<?= $i ?>">edit</button> </form> <?php $i++; } ?> For the second question: if you want to pass...

You can get a total average number of events per second like this: #!/usr/bin/env python3 import time import datetime as dt start_time = dt.datetime.today().timestamp() i = 0 while(True): time.sleep(0.1) time_diff = dt.datetime.today().timestamp() - start_time i += 1 print(i / time_diff) Which in this example would print approximately 10. Please note...

Glad you found an answer. Here is something I was working on while you found it. // SET START DATE $startDate = new DateTime($dateStart); $nextBill = new DateTime(); for($i=1;$i<$countDays;$i++){ switch(true){ case ($startDate->format('j') > $days[2]): // go to next month $nextBill->setDate( $startDate->format('Y'), $startDate->format('m')+1, $days[0]; ); break; case ($startDate->format('j') > $days[1]): //...

You are getting this output because you are overwriting the keys in your array. You would need to save to another array (aka not 2-dimensional): <?php $tbl = "TranslationsMain"; $conn = new mysqli($servername, $username, $password, $dbname); if($conn->connect_error){ die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM " ....

Calling open(output.txt) returns a file object, not the the text within the file. Calling str on the file object just gives a description of the object, not the text. To get that you need to something like output = open('output.txt') past_results = output.read() Also, it looks like you're calling str...

A small semantic correction - the compiler isn't throwing any exception - your code compiles just fine. The runtime execution of this code causes an exception. And more to the point, an array a has elements from 0 to a.length - 1. Your code attempts to access element number a.length...

In Lua, the order that pairs iterates through the keys is unspecified. However you can save the order in which items are added in an array-style table and use ipairs (which has a defined order for iterating keys in an array). To help with that you can create your own...

It will enter the for loop first when i = 0. Immediately after it will enter the while loop and continue running indefinitely as i will always be 0 and therefore < 3. You perhaps need to deal with j in the break condition of inner loop for avoiding an...

If the Cells.Find(What:="Run:" & i,... fails to find a match, the Select part of the statement will then cause the error. You should always store the result of a Find in a range variable and then test that for Nothing. Add this declaration to your code: Dim cellsFound As Range...

To create variables by string, you can use - globals() function , which returns the dictionary of global namespace, and then create a new element in that dictionary for your variable and set the value to the value you want. Also , you can directly call - pandas.DataFrame(Series) - and...

You could just check the nesting level by counting parents $("ul li").each(function() { if ( $(this).parents('ul').length < 3 ) { // do stuff } }); FIDDLE To make it more dynamic one could simply find the deepest nesting level and filter based on that var lis = $("ul li"); var...

I'll assume you have a list of each loop variable and its maximum value, ordered from the outermost to innermost variable. loops <- list(a=2, b=3, c=2) You could create a data frame with all the loop variable values in the correct order with: (indices <- rev(do.call(expand.grid, lapply(rev(loops), seq_len)))) # a...

You can use itertools.count() for that. It creates a generator, that just returns one number after the other, when you call it's next() method: from itertools import count counter = count(1) for row in rows: row_id = counter.next() In this example on every iteration through the rows you will get...

User has many photos @user.photos.count #as user has_many photos From loop with index of each photo object @user.photos.map.with_index.to_a #[[photo1, 0], [photo2, 1]] To get total count/ or total iteration of photos @user.photos.map.with_index(1).to_a.last.last You can find enumerator#with_index...

You seem to be fond of for loops and those seem like a natural choice here. Just change your code to this: for(i in 1:nrow(matSolo)){ for(j in 1:ncol(matSolo)){ if(SoloNight[i,j] == 1) { matSolo [i,j] <- 1 break } } } However, this will be quite slow for big matrices. Fortunately,...

There is already a handy formula for least squares fitting. I came up with two different ways to solve your problem. For the first one, consider the matrix K: L = len(X) K = np.identity(L) - np.ones((L, L)) / L In your case, A and B are defined as: A...

If you made the if statements equivalent, I'd say the top version is more generic and better for more complex statements due to the following: If you had multiple if - continue statements, the first approach would allow you to list them in order without nested indentation which could keep...

So it turns out I was wrong in my other comment. The non-detection of edges was causing you to index into unset parts of your array causing those weird messages and was all of your problems I scaled it back a bit to look at it see https://jsfiddle.net/goujdwog/2/ the important...

The problem is here: for (int hcount = 0; hcount < height; hcount++); You end the loop with ;, which is a no-op. The hcount is in any case visible only in the scope of the loop. After the loop execution (i.e. after ;), the inner loop starts executing. Your...

For the first instance, try this: print('', end = '') For the second instance, the mistake is that you are adding 0 to the second for loop. Change it to: for j in range(0, 1+i): The thing with range is that it goes until one number lower. Have a look...

Yes, you need a variable, and just concatenate it. Use something like this: Dim counter as long counter = 1 Cells.Find(What:="Run:" & counter, After:=Cells(1, 1), _ ...yaddayadda Or use it in a loop: For i=1 to 100 Cells.Find(What:="Run:" & i, After:=Cells(1, 1), _ ...yaddayadda Next i ...

In your code, you need to change the for loop condition checking expressions, like i == lenstr and later i==0. They are not entering the loop, essentially. Instead, you can replace the whole block for(i = 0;i == lenstr;i++) { str2[i][j] = str[i]; j = j + 1; } for(i...

Why don't you just do it in one single query? Just replace the necessary table and column name, and variables/values/parameters to be bind in your query: $query = mysqli_query($conn, "SELECT first_name, last_name, description, role FROM `wp_usermeta` WHERE `first_name` = '$first_name' OR `last_name` = '$last_name' OR `description` = '$description' OR `role`...

The second condition should be changed, otherwise the third if won't be reached. Also the third condition should be changed to check if the daysLate variable is greater or equal to zero: if (daysLate > 90) { costDue = bookPrice + 10; } else if (daysLate >= 7) { costDue...

Here's a recommended way to ask a question, focusing on the fact that your actual data is too big, too complicated, or too private to share. Question: how to apply a function on each row of a data.frame? My data: # make up some data s <- "Lorem ipsum dolor...

Wrap the script into a function by putting: my_function <- function(latitude) { at the top and } at the bottom. That way, you could source it once then then use ldply from the plyr package: results <- ldply(10 * 5:8, myFunction) If you wanted a column to identify which latitude...

the problem that I see if I understand what you are trying to do is the way you are dumping idea.evaluations into @idea_evaluations. @idea_evaluations is going to be an array of arrays of evaluations not an array of evaluations as you think. e.g. [[eval1,eval2],[eval3,eval4,eval5]] instead of [eval1, eval2, eval3, eval4,...

One option would be to make your function(response) recursive. When it runs, call this same method again. Pass in some of your "looping" variables, and just do an if check at the beginning. function AnotherGoRound(i,data) { if (i<data[i2].data.length) { console.log("SENDING: i=" + i + "; i2=" + i2); // Send...

I'd use the getTime object in JS I believe I have the time set right in this JSFiddle var d = new Date(); var year = d.getFullYear(); // Month 0 = January | Month 11 = December | so I changed vallues by +one var month = d.getMonth() +...

It's generally not a good idea to try to add rows one-at-a-time to a data.frame. it's better to generate all the column data at once and then throw it into a data.frame. For your specific example, the ifelse() function can help list<-c(10,20,5) data.frame(x=list, y=ifelse(list<8, "Greater","Less")) ...

You should create the image object within the for loop because if it is not then it is using the same object multiple times See demo Change you jQuery to this, $(document).ready(function () { for (i = 0; i < 12; i++) { var myImage = new Image(); myImage.src =...

If you want set "Yes" to one of picture from pictures array, you should use code like this; $bestscorelike = 0; $bestPictureObject = null; foreach($pictures as $picture) { $scorelike = $picture->getScorelike(); if($scorelike > $bestscorelike) { /** * Now in the $bestPictureObject exists picture with scorelike less then current $picture */...