BB___Variables

=Variables= toc

Description
> A variable is a programming element which can have a value that is not fixed. The variable can be changed during the running of the program by assigning a new value to the variable name. > Variables can be either string or numeric type.

Syntax
Numeric type: String type:

Hints
> A name must start with a letter, but it can contain letters and numbers. > You cannot use underscore ( _ ) in a variable name. > Variable names are case sensitive; name$ is not the same as NAME$ or Name$. > Having short variable names saves typing and lessens chance of misspelling; having descriptive variable names could make code more readable. Finding right balance is up to you. > The length of variable name in JB seems not restricted. > A standard naming practice is to use what is called "camel casing" (I suppose because the name looks "humpy"). This practice involves using multiple word names and capitalizing each word after the first. Like this: >> code myVariableName code > A practice often used with other programming languages uses a dot to separate the descriptive words of a variable name. Like this: >> code my.firstName$ code > While in "other programming languages" dot usually represent nesting of objects, in JB it could be used for decoration only. Test shows that you can use several dots, several dots in a row and even end variable name with dot. (It is not common among other languages and will sure make your code less portable). >> code format="lb" numVar = 3 numVar = var1 numVar = (numVar * var1 + 4) code >> code format="lb" name$ = "Bob Smith" number$ = "22" firstName$ = word$(name$, 1) code
 * //**Naming Conventions.**// Generally, variable names should be chosen to give a hint as to what the contents may be.
 * //**Numeric Variable.**// A numeric variable does not have a "$" appended to the name. It can hold a literal value, another variable value, or an expression. Some examples:
 * //**String Variable.**// A string variable must have a "$" appended to its name. String variables can hold literal characters which must be enclosed in double quotes. They can also hold other string variable values. Some examples:
 * //**Undefined variable.**// Variable, what does not assigned a value, is called "undefined". Undefined numeric variables return value 0 (zero); undefined string variable returns "" (empty string). Error in spelling variable name usually creates undefined variable.
 * //**Variable Scoping.**// In addition to using care with variable name spelling, you must also be aware of where a variable can be used in your program. In general, variables used in the main program will not be recognized in functions or subroutines; they are said to be not visible in subs and functions. An exception is when a variable is declared GLOBAL. For a discussion of scoping, see GLOBAL.

Example
code format="lb" firstName$ = "Bob"

print "Is your name "; firstName$; "?"

print "If your name is not "; firstName$; " then type your name after the prompt:" input "My name is "; firstName$

print "OK. So your name is "; firstName$ print "Goodbye" code

Useful Functions
code format="lb" Place a useful function using this keyword here code