How to correctly declare a variable in Swift?

I found quite interesting these different ways to declare a variable in Swift: // METHOD 1 var dogName: String = "Charlie" // METHOD 2 var dogName: String { return "Charlie" } // METHOD 3 let dogName = { return "Charlie" } //

Must declare the scalar variable @ when updating the table

I have this code: connection.Open(); string query = "UPDATE [dbo].[EmailPassword] SET HashedPassword = @hashedPassword, Salt = @salt, ForgotHisPassword = @forgotHisPassword where Email = @email"; SqlCommand command = new SqlCommand(query, connec

Is a loop of loops unique

I ran into this while performing some technical debt duties. What is the scope of the variable foo ? Is it really "already defined"? function fn(){ for (var i = 0; i < m.length; i++) { if(condition) for (var j = 0; j < m.length; j++) { var

Is there a fundamental type for natural numbers in C / C ++?

I have a problem in which I need to declare some variables as natural numbers. Which is the propper fundamental type that I should use for variables that should be natural numbers ? Like for integers is int ...Notice that a computer (and perhaps even

Iterator and type of iterator

if I have an iterator of some container with unknown class within it, can I declare a variable of that unknown type by: *Iterator unknown_type_var; The unknown_type has default ctor, so that isn't the issue. But do a method like this exist ? Or is th

int [] table = new int [10], x; is the valid syntax?

When I initialize a new array I noticed if I put a ,x it still compiles. I'm not sure what is happening here. int[] table = new int[10],x; for(int x=1; x<11; x++){ System.out.println("Count is: " + x); } If I try running this it says that x i

VariableDeclaratorID exception in java while loop

I have declared a String array globally. And inside a method in while loop when i tried to assign some value, it shows VariableDeclaratorID expected after this token. //global declaration String name[]; While (scanner.hasNextLine()){ String input = s

Empty hash declaration

I've never known the difference, if there is one, between the following: my %hash; my %hash = (); Could anyone shed some light on this?In some languages, new variables are provided uninitialized. In Perl, scalars are created undefined, and array and

Is the definition of a boolean on false redundant?

I have read several previously asked questions and answers on this topic [or quite similar], but none of them have really addressed this point-blank. When declaring a new boolean varibale, is it redundant [e.g. unnecessary] to initialize it to false?

GUI - JFrame: declaration of variables

In the following code I have created 3 variables: public class tuna extends JFrame { //Creating 3 text fields private JTextField item1; private JTextField item2; private JTextField item3; what I dont understand is why I then need to do the following:

Problems with onListItemClick (mNotesCursor)

i am using the developer.android Notepad tutorial (http://developer.android.com/training/notepad/notepad-ex2.html) to create a Noteapp, but i have problems with the onItemClick and i cant figure out, where the problem lies. My Code public class MainA

Allowed types in loop variable declarations?

I've done some searches and couldn't find a list of valid types to use in for loop initialization statements. Is there a fixed list of types that can be used in for loop variable declarations? For instance, consider the following code: for (int i = 0

Setting the result data type in the `function` statement

Well, let me say first why I want to do this. I frequently write code in C/C++, so for me it's very natural to define functions like: vector<int> TestFunct (int a, int b){ <some code here> return <result>;} Now I'm learning Fortran, so I

double as true / false

Bjarne suggests using the condition in if's as scope restriction. In particular this example. if ( double d = fd() ) { // d in scope here... } I'm curios how to interpret the declaration in a true / false sense. It's a declaration It's a double. Edit

What is the difference between int * ptr and int * ptr in C?

I am fairly new at C and I don't know the difference between the following two variable declarations: int* ptr; int *ptr; I think that in the declaration int* ptr;, ptr's value cannot be changed whereas it can be changed for the declaration, int *ptr

Excel-VBA: Variable declaration needed?

Would it be wrong if write the following code Sub Something() Dim i As integer Dim xRange As Range Dim yRange As Range Set xRange= Range("x_table") Set yRange= Range("y_table") For i = 1 To xRange.Columns.Count xRange.Columns(i) = Appl

Lambda closure or class level variable?

Just a general question about what the best practice is: public void Foo() { int x = 5; myControl.Click += (o, e) => { x = 6; }; } Notice, I'm using the x variable inside my lambda event handler. OR: public class Bar { private int x = 5; public void