loops

Looping over unique pairs of elements in a list in R

大憨熊 提交于 2020-12-30 04:44:31
问题 Suppose I have a list of objects called bb . I want to pick each unique pair of elements in bb and use them in some kind of function (called convolve ) as shown below: ## Below `bb` elements: `bma1` & `bma2` are used in the function: con <- convolve(dens1= bb$bma1$dposterior, dens2= function(x){bb$bma2$dposterior(-x)}, cdf1= bb$bma1$pposterior, cdf2= function(x){1 - bb$bma2$pposterior(-x)}) con$quantile(c(0.025, 0.975)) Question: bb can have any number of elements but convolve() accepts only

Syntax for a one-line infinite detached loop

一曲冷凌霜 提交于 2020-12-27 07:02:19
问题 I could run something in endless loop like this: $ while true; do foo; done I could run something detached like this: $ foo & But I can't run something detached in endless loop like this: $ while true; do foo & ; done -bash: syntax error near unexpected token `;' How to run an infinite detached loop in one line of shell code? 回答1: & is a terminator like ; , you can't mix them. Just use while : ; do foo & done I'd add a sleep somehwere, otherwise you'll quickly flood your system. 回答2: If you

Syntax for a one-line infinite detached loop

烈酒焚心 提交于 2020-12-27 07:00:28
问题 I could run something in endless loop like this: $ while true; do foo; done I could run something detached like this: $ foo & But I can't run something detached in endless loop like this: $ while true; do foo & ; done -bash: syntax error near unexpected token `;' How to run an infinite detached loop in one line of shell code? 回答1: & is a terminator like ; , you can't mix them. Just use while : ; do foo & done I'd add a sleep somehwere, otherwise you'll quickly flood your system. 回答2: If you

Nested Loops Using Loop Macro in Common Lisp

点点圈 提交于 2020-12-26 09:38:44
问题 I am trying to implement a basic nested loop in CL, but the Loop macro is resisting this. Basically, I would like to find all possible products of 3-digit numbers and accumulate them into a list. Here is my attempt: (loop for x downfrom 999 to 998 do (loop for y downfrom 999 to 998 collect (* x y))) The code above returns NIL for some reason. By the way, I realize that I only run down to 998, but this is done for testing purposes. What could I do to obtain a list like this: (999*999 999*998 .

Nested Loops Using Loop Macro in Common Lisp

我是研究僧i 提交于 2020-12-26 09:38:23
问题 I am trying to implement a basic nested loop in CL, but the Loop macro is resisting this. Basically, I would like to find all possible products of 3-digit numbers and accumulate them into a list. Here is my attempt: (loop for x downfrom 999 to 998 do (loop for y downfrom 999 to 998 collect (* x y))) The code above returns NIL for some reason. By the way, I realize that I only run down to 998, but this is done for testing purposes. What could I do to obtain a list like this: (999*999 999*998 .

Iterate over dictionary of objects

谁说我不能喝 提交于 2020-12-26 06:21:25
问题 I have a dictionary of objects which contains the "Names/Ranges" within a spreadsheet. As I process the spreadsheet I need to update the value associated with a range. The class to hold this info looks like this: class varName: name = None refersTo = None refersToR1C1 = None value = None def __init__(self, name, refersTo, refersToR1C1, value): self.name = name self.refersTo = refersTo self.refersToR1C1 = refersToR1C1 self.value = value I create the dictionary as follows: staticNames = {}

Infinite loop when using size_t in a count down for loop

旧巷老猫 提交于 2020-12-25 10:54:36
问题 So I'm using size_t instead of int in any indexing for loop to prevent negative indices. But when counting down, this leads to an overflow: for (size_t i = 10; i >= 0; --i) { // Do something, f.ex. array[i] = i } What would be a nice way to prevent this? Using int instead? Using i == 0 as the termination condition? (This would however not work if I need the 0) I'd appreciate any feedback! 回答1: for (size_t i = 10; i <= 10; --i) // do something When overflow do happens, it will round to the

Infinite loop when using size_t in a count down for loop

萝らか妹 提交于 2020-12-25 10:53:38
问题 So I'm using size_t instead of int in any indexing for loop to prevent negative indices. But when counting down, this leads to an overflow: for (size_t i = 10; i >= 0; --i) { // Do something, f.ex. array[i] = i } What would be a nice way to prevent this? Using int instead? Using i == 0 as the termination condition? (This would however not work if I need the 0) I'd appreciate any feedback! 回答1: for (size_t i = 10; i <= 10; --i) // do something When overflow do happens, it will round to the

Not block UI while loop in .Net Windows Forms

六月ゝ 毕业季﹏ 提交于 2020-12-25 05:42:08
问题 I have a pretty heavy loop in my button click event that takes about 1-2 minutes to complete (loops around 50000 times): while (continue) { if (xlRange.Cells[i, j].Value2 == null) continue = false; else { pbar.PerformStep(); string key = xlRange.Cells[i, j].Value2.ToString(); Random r = new Random(); bool ok = r.Next(100) <= 2 ? false : true; if (!ok) { this.dataGridView1.Rows.Add(x + 1, key); x++; groupBox2.Text = "Error (" + x + ")"; } i++; } } The loop locks the UI and it is not possible

Use of php variable $_ (dollar sign followed by an underscore)

余生长醉 提交于 2020-12-25 01:50:20
问题 Is that really true that i can use $_ as a dummy variable in foreach loop if there is no need for $value in foreach($array as $key => $value) ? I could not find any useful information that proves this except PHP syntax formatting. There's a special case for foreach loops when the value is not used inside the loop. In this case the dummy variable $_ (underscore) is used: foreach ($GLOBALS['TCA'] as $table => $_) { // Do something with $table } This is done for performance reasons, as it is