for-loop

create a loop to space 2 different objects on a uiviewcontroller

不打扰是莪最后的温柔 提交于 2020-01-06 05:25:29
问题 My code below does exactly what I am looking for the problem is it just does this in a uibtton. I would like to do the same thing with 2 uitextfields and 2 uilabels. So textfield to uilabel to textfield to uilabel. I assume you would just have to change "button in" but I dont know what to change it with. I want the objects spaced 40 between each other just like below. func setConstraints() { var yPosition: CGFloat = 0 [undoButton, clearButton, color].forEach { button in NSLayoutConstraint

Parametric nested loops in Python

纵饮孤独 提交于 2020-01-06 05:21:17
问题 One parameter in my model controls the dimension of arrays; it can vary from 1 to any positive integer: for my purposes this can be up to 20. The flow of the program goes through a number of loops that depend on this dimension. For example, if the value of the parameter is one I would have: for i1 in range(0,100,1): do stuff If the value of the parameter is two, then I would have something like: for i1 in range (0,100,1): for i2 in range (0,100,1): do stuff Or, if the value of the parameter

Break and return inside multiple for-loops with conditional statement

大城市里の小女人 提交于 2020-01-06 05:04:34
问题 I have created a long code, consist of multiple lists inside for-loops. There are nothing wrong with calculation.It does obtain results as it is expected to. The code and construction of lists work fine. The problem is when it runs, I have defined a break when a certain condition is matched. But it does not break at first run, continues and run through all values within range function of first loop. I want to achieve to return a true value, when the condition is matched, and stops and will

Break and return inside multiple for-loops with conditional statement

不打扰是莪最后的温柔 提交于 2020-01-06 05:04:27
问题 I have created a long code, consist of multiple lists inside for-loops. There are nothing wrong with calculation.It does obtain results as it is expected to. The code and construction of lists work fine. The problem is when it runs, I have defined a break when a certain condition is matched. But it does not break at first run, continues and run through all values within range function of first loop. I want to achieve to return a true value, when the condition is matched, and stops and will

Finding duplicates in java Array

好久不见. 提交于 2020-01-06 03:11:10
问题 Anyway, I have this extremely simple java program to find out if 2 objects in an array are the same. How ever when I run it when a set of unique objects it always returns 1 error, If I add more objects that are the same it counts as normal. This is the code; int[] array= new int[] {1,245,324,523}; int size = array.length; int error=0; System.out.println(error); int i = 0; for(i=0; i<size; i++){ if(array[0] == array[i]){ error= error +1; } System.out.println(error); } 回答1: The 1 error is

Stop loop when condition variable (global var) changes in javascript

孤人 提交于 2020-01-06 01:32:11
问题 I'm having a problem that I can't solve. I have a loop in javascript where the condition variable to stop depends on a global variable. The loop starts looping and when I change the value of that global variable it never stops. stop = false; var i = 0; while ((stop == false) && (i<100000)){ console.log("hi-"+i); i++; } While loop is running, if I do stop = true, it never stops. I do not know why is that. Any idea? Thanks! 回答1: JavaScript is inherently single threaded. Once a block of code has

Python: list iteration only returns last value

末鹿安然 提交于 2020-01-05 17:45:14
问题 I'm using scikit-learn for GMM training and am trying to vary the number of mixture components by looping over a list of integers. But when I print my resulting models I only get the ones with 3 mixture components, or whatever I put as the last item in my list. This is my code: from sklearn.mixture import GMM class_names = ['name1','name2','name3'] covs = ['spherical', 'diagonal', 'tied', 'full'] num_comp = [1,2,3] models = {} for c in class_names: models[c] = dict((covar_type,GMM(n

R for loop: create a new column with the count of a sub str from a different column

假装没事ソ 提交于 2020-01-05 10:25:11
问题 I used to fiddle with R and now it all seems to have escaped me . . . I have a table with a few hundred columns and about 100k rows. One of those columns contains strings that sometimes have commas in them (e.g. chicken,goat,cow or just chicken). I need a script with a (I believe) for loop that can create a new column (I know the new column code should not be in the for loop), count the number of commas (or the number of entries in the column in question less one) and add one so I can find

Create columns in R within a for loop

两盒软妹~` 提交于 2020-01-05 10:11:28
问题 I have a data frame in R and I would like to create new columns within a for loop. I have tried many things for the last 2 days but without success. At the end, I did find a solution that seems to work, but it doesn't seem very straight forward. I was wondering if anybody has a more elegant way to do this. Sorry if this has already been addressed but I couldn't find similar question on SO Here is my example. x <- runif(20) a <- as.data.frame(x) for (i in 1:100){ d <- x + i a <- cbind(a, d) }

Create columns in R within a for loop

冷暖自知 提交于 2020-01-05 10:11:06
问题 I have a data frame in R and I would like to create new columns within a for loop. I have tried many things for the last 2 days but without success. At the end, I did find a solution that seems to work, but it doesn't seem very straight forward. I was wondering if anybody has a more elegant way to do this. Sorry if this has already been addressed but I couldn't find similar question on SO Here is my example. x <- runif(20) a <- as.data.frame(x) for (i in 1:100){ d <- x + i a <- cbind(a, d) }