<< Click to Display Table of Contents >> Navigation: Concordance Programming Fundamentals > Declaring and using a Variable > Assigning a Variable |
Once you have declared a variable, you may assign that variable a value.
1.Use the equals sign (=) to assign a value, as you would in mathematics.
i.Be sure that the type of data you are attempting to assign to a variable matches up with the variable type. for example, you should not attempt to assign an integer to a variable that was declared as text.
2.When assigning a value to a text variable, be sure to use double-quotes at the beginning and ending.
3.When assigning a value to a char, be sure to use single-quotes at the beginning and ending.
i.The following examples describe various ways of assigning a value to a variable.
x = 2; myString = "hello"; aFloat = 3.1415; myChar = 'a';
x = "hello"; /* BAD! Don't do this */ |
In addition to directly assigning a value, you can perform basic mathematical operations, and assign the result to a variable. For more information, see Performing Math with Variables.