variable-assignment

What does => (equals greater than) mean in Fortran?

十年热恋 提交于 2019-11-29 06:39:38
I'm looking through some old Fortran 90 code and have come across the => symbol: var => item It looks like it's being used for some sort of assignment. Searching Google for "arrow symbol Fortran" or "equals greater than symbol Fortran" gives me no related material. => appears in six contexts as a syntactic element in modern Fortran, many, but not all, related to pointers: pointer assignment ; pointer initialization ; procedure (pointer) declaration ; type-bound procedure declaration ; association ; renaming . There is close connection between most of these. Loosely, in many => can be viewed as

php array assign by copying value or by reference? [duplicate]

微笑、不失礼 提交于 2019-11-29 06:19:38
Possible Duplicate: are arrays in php passed by value or by reference? I heard that PHP can select how to assign arrays, depends on array size. It can assign by copying value (as any scalar type) or by reference. PHP always assign array to variables by copying a value, as it says in manual. Or it can assign by reference. ? <?php $a = array(1,2,3); ?> Michael Berkowski Assigning arrays by reference is possible when assigning array variables to other variables: // By value... $a = array(1,2,3); $b = $a; array_push($a, 5); print_r($b); // $b is not a reference to $a Array ( [0] => 1 [1] => 2 [2]

Which costs more while looping; assignment or an if-statement?

我怕爱的太早我们不能终老 提交于 2019-11-29 06:16:54
问题 Consider the following 2 scenarios: boolean b = false; int i = 0; while(i++ < 5) { b = true; } OR boolean b = false; int i = 0; while(i++ < 5) { if(!b) { b = true; } } Which is more "costly" to do? If the answer depends on used language/compiler, please provide. My main programming language is Java. Please do not ask questions like why would I want to do either.. They're just barebone examples that point out the relevant: should a variable be set the same value in a loop over and over again

Python: Assign Value if None Exists

我怕爱的太早我们不能终老 提交于 2019-11-29 05:48:23
问题 I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn't previously assigned. Basically I want: # only if var1 has not been previously assigned var1 = 4 回答1: This is a very different style of programming, but I always try to rewrite things that looked like bar = None if foo(): bar = "Baz" if bar is None: bar = "Quux" into just: if foo(): bar = "Baz" else: bar = "Quux" That is to say, I try hard to avoid a

Python Assign value to variable during condition in while Loop

こ雲淡風輕ζ 提交于 2019-11-29 05:33:59
A simple question about Python syntax. I want to assign a value from a function to a variable during the condition for a while loop. When the value returned from the function is false, the loop should break. I know how to do it in PHP. while (($data = fgetcsv($fh, 1000, ",")) !== FALSE) However when I try a similar syntax in Python I get a syntax error. You cannot use assignment in an expression. Assignment is itself a statement, and you cannot combine Python statements. This is an explicit choice made by the language designers; it is all too easy to accidentally use one = and assign, where

Correct way to trim a string in Java

非 Y 不嫁゛ 提交于 2019-11-29 05:01:36
问题 In Java, I am doing this to trim a string: String input = " some Thing "; System.out.println("before->>"+input+"<<-"); input = input.trim(); System.out.println("after->>"+input+"<<-"); Output is: before->> some Thing <<- after->>some Thing<<- Works. But I wonder if by assigning a variable to itself, I am doing the right thing. I don't want to waste resources by creating another variable and assigning the trimmed value to it. I would like to perform the trim in-place. So am I doing this right?

“Y does not name a type” error in C++

末鹿安然 提交于 2019-11-29 03:42:58
I don't know what to search to find an explanation for this, so I am asking. I have this code which reports error: struct Settings{ int width; int height; } settings; settings.width = 800; // 'settings' does not name a type error settings.height = 600; // 'settings' does not name a type error int main(){ cout << settings.width << " " << settings.height << endl; but if I put the value assignment in main, it works: struct Settings{ int width; int height; } settings; main () { settings.width = 800; // no error settings.height = 600; // no error Can you explain me why? EDIT: Regarding to Ralph

c# multi assignment

微笑、不失礼 提交于 2019-11-29 03:19:10
int a, b, n; ... (a, b) = (2, 3); // 'a' is now 2 and 'b' is now 3 This sort of thing would be really helpfull in C#. In this example 'a' and 'b' arn't encapsulated together such as the X and Y of a position might be. Does this exist in some form? Below is a less trivial example. (a, b) = n == 4 ? (2, 3) : (3, n % 2 == 0 ? 1 : 2); Adam Maras shows in the comments that: var result = n == 4 ? Tuple.Create(2, 3) : Tuple.Create(3, n % 2 == 0 ? 1 : 2); Sort of works for the example above however as he then points out it creates a new truple instead of changing the specified values. Eric Lippert

Is there a name for “this” in Java?

泪湿孤枕 提交于 2019-11-29 01:06:36
Eclipse will give an error, "The left-hand side of an assignment must be a variable", when I try something like: public class Thing{ String a1; int a2; public void meth(){ Thing A = new Thing(); this = A; } } I had to assign each variable ( this.a1 = A.a1; this.a2 = A.a2; ) as a work around. Are there other ways to do this without going through each variable field? And if this is not a variable what is it called? this is a pseudo-variable that points to the current instance of the object, it can not be reassigned. It's also considered a keyword in the language, according to section §3.9 of the

Assignment of a struct value to this keyword

爱⌒轻易说出口 提交于 2019-11-29 00:09:17
I was recently looking into internals of CancellationToken structure and discovered a bit of weird construct (to be more precise, assignment of value to this keyword). Code of one of its constructors is as following: public CancellationToken( bool canceled ) { this = new CancellationToken(); if ( canceled ) { this.m_source = CancellationTokenSource.InternalGetStaticSource( canceled ); } } What is the meaning of line on which the assignment to this keyword occurs? Please note that assignment to this keyword is not possible for classes - error Cannot assign to '<this>' because it is read-only