Line numbers and Labels

Line numbers are Integers in the range 1 to 65535, which serve to identify program lines.  PowerBASIC takes a relaxed stance toward line numbers.  They can be freely interspersed with labels, and used in some parts of a program and not others.  In fact, they do not even need to follow in numeric sequence.  No two lines can have the same number, and no line can have both a label and a number.  Line numbers are essentially labels.

While line numbers and labels serve the same purpose, their usage is slightly different.  Line numbers are really just a concession to compatibility with Interpretive BASIC.  Line numbering can lead to bad programming style.  Since the numbers themselves can be in any order, they give a false sense of structure to a program.  We recommend that you avoid line numbers, and use labels instead.

Labels and line numbers are local to a procedure, so the same line number or label can be used in more than one Sub or Function.  However, you cannot use the same name for a label and a global or threaded variable.

Using labels instead of numbers allows you to make the flow of your program much more readable.  For example:

GOSUB BuildQuarks

tells you much more than

GOSUB 1723

Each label must appear on a line by itself (though a comment may follow) and it serves to identify the statement immediately following it.  Labels must begin with a letter and contain any number of letters, digits, and an underscore.  Case is insignificant - THISLABEL, thislabel, and ThisLabel are all treated the same.  A colon must follow a label, and statements, which refer to the label, must not include the colon.

PRINT "Now Sorting Invoices"

GOSUB SortInvoices

PRINT "All Done!"



SortInvoices:  ' This is a legal label

  {sorting code goes here}


The following is illegal, however:

ExitPoint:  a = a + 1  ' a label must be on a line by itself

Finally, it should be noted that symbol names must be unique: a label may not share the name of any other symbol (Sub name, Function name, user-defined type or union definition, variable name, etc), and they are local to the Sub or Function in which they appear.


See Also

Writing Programs in PBCC

Long lines