variable-assignment

Performance: condition testing vs assignment

拜拜、爱过 提交于 2019-12-10 10:49:34
问题 I've created a loop where a variable is used to test if the current run-through of the loop is the first one. Its fairly simple: $firstrun = true; while(condition){ if($firstrun) // Do this else // Do that // Change $firstrun to false } I was just wondering (mostly out of curiosity because I'm it makes no real noticeable difference), when I need to change $firstrun to false, would be more efficient to test if the variable is true before assigning it to false or simply reassign it to false

Use %2* in string variable in Windows batch file

浪子不回头ぞ 提交于 2019-12-10 10:36:11
问题 I'm trying to create a simple script in batch to run in Windows, the script has 3 variables: the URL to open the number of windows to open the time to wait until the new window is open The script works fine except when the URL contains characters like %20 or %2F in which I guess cmd.exe is trying to use them as variables, I'm putting the value of the URL between quotes but that didn't help. If I use the address: set url="http://domain.com/app.html?path=%2F%2Flocalhost%2Fcode&do_pause=false&go

Update 'x'th element of list - Haskell [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-10 10:00:40
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Replace individual list elements in Haskell? I have managed to make some progress in this part of my assignment but have attached part of the code below that I have made: module Grid where data State = On | Off deriving (Eq, Show) next :: State -> State next On = Off next Off = On type Row = [State] updateRow :: Row -> Int -> Row updateRow (r:rs) x | x == 0 = next r:rs -- | otherwise = ........???? As shown in

How to set a variable equal to the contents of another variable?

允我心安 提交于 2019-12-10 09:31:34
问题 In the following (simplified example) batch file I am having difficulty correctly setting Y : @Echo off setlocalenabledelayed Expansion set EqS=Nope set X=Eq set Y=%X%S echo Y How can I get the output of this script to be Nope instead of EqS ? 回答1: As Karl ask, there could be different meanings of your question. I try to give an answer for each possibility @echo off setlocal EnableDelayedExpansion set EqS=Nope set X=Eq REM set Y1 to "EqS" set Y1=%X%S REM set Y2 to "Nope" (content of EqS) set

Is it better to assign variables in a class itself or in the class' constructor? [closed]

会有一股神秘感。 提交于 2019-12-10 09:24:44
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . This is a sort of design question, and I'm sure there are people who do it both ways. But in your opinion, is it better to assign a variable in the class or in the constructor? For example (regardless of syntax or language, this is just to explain): public class Example {

Python variable assignment question

喜欢而已 提交于 2019-12-10 06:18:10
问题 a,b = 0,1 while b < 50: print(b) a = b b = a+b outputs: 1 2 4 8 16 32 wheras: a,b = 0,1 while b < 50: print(b) a,b = b, a+b outputs (correct fibonacci sequence): 1 1 2 3 5 8 13 21 34 Aren't they the same? I mean a,b = b, a+b is essentially the same as a = b and b = a+b written separately -- no? 回答1: No, they are not the same. When you write a,b = b, a+b , the assignments are done "simultaneously". a,b = b, a+b is same as (a, b) = (b, a+b) . So, after a, b = 5, 8 a=5 and b=8. When Python sees

How to group 'Option' assignments in Rust?

寵の児 提交于 2019-12-10 03:39:45
问题 I have a block of code where multiple optional variables need to be assigned at once. There is very little chance any of the values will be None , so individually handing each failed case isn't especially useful. Currently I write the checks like this: if let Some(a) = foo_a() { if let Some(b) = foo_b() { if let Some(c) = foo_c() { if let Some(d) = foo_d() { // code } } } } It would be convenient if it was possible to group assignments. Without this, adding a new variable indents the block

Object property assignment with destructuring?

為{幸葍}努か 提交于 2019-12-10 03:39:34
问题 I'd like to use ES6 destructuring to assign properties of an object, but can't figure out the syntax. <= ES5: var dst = {}; // already in existence, with its own props, methods, etc. var src = { a: 'foo', b: 'bar', c: 'baz' }; dst.a = src.a; dst.b = src.b; >= ES6 (my own made-up, not-working syntax): let dst = {}; let src = { a: 'foo', b: 'bar', c: 'baz' }; dst[{a, b}] = src; Is it possible to use destructuring assignment onto an object? What's the correct syntax? EDIT: In my use case, dst is

error: cannot assign a value to final variable

耗尽温柔 提交于 2019-12-10 03:05:50
问题 I am working on an assignment and I'm stuck on this error: cannot assign a value to final variable count Here is my code so far... public class List { private final int Max = 25; private final int count; private Person list[]; public List() { count = 0; list = new Person[Max]; } public void addSomeone(Person p) { if (count < Max){ count++; // THIS IS WHERE THE ERROR OCCURS list[count-1] = p; } } public String toString() { String report = ""; for (int x=0; x < count; x++) report += list[x]

Is chained assignment in C/C++ undefined behavior?

橙三吉。 提交于 2019-12-09 17:08:58
问题 Ignoring the types of variables, is expression like a=b=c has defined behavior in both C and C++? If so, can any one give me official evidence, like quotes from the standard, please? P.S. I searched the chained assignment but everything I got is associativity, but I didn't find any text about that in the C99 standard. Maybe I did it wrong? hoping anyone can help me. 回答1: From the C++ Standard 5.17 Assignment and compound assignment operators [expr.ass] 1 The assignment operator (=) and the