1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-26 17:55:52 +00:00
QB64-PE/internal/help/CONST.txt
SMcNeill 6e01fc8dce Altered string compare routines (<,<=,>,>=) so they don't give false results with CHR$(0).
Added new _STRCMP and _STRICMP commands for quick string comparisons.
Cleaned up QB64 to finish removing the QUI (quick user insert) code and folders.
Altered UCASE and LCASE routines to be faster in some situations for us.
2014-09-22 08:19:03 -04:00

59 lines
2.6 KiB
Plaintext

The {{KW|CONST}} statement globally defines one or more named numeric or string values which will not change while a program is running.
{{PageSyntax}}
: '''CONST {{Parameter|constantName}} = {{Parameter|value}}'''[, ...]
{{Parameters}}
* {{Parameter|constantName}} is the constant name or list of names assigned by the programmer.
* {{Parameter|value}} is the value to initialize the global constant which cannot change once defined:
** If {{Parameter|constantName}} specifies a numeric type, {{Parameter|value}} must be a numeric expression containing literals and other constants.
** If {{Parameter|constantName}} specifies a string type, the {{Parameter|value}} must be a literal value.
''Usage:''
* The {{Parameter|constantName}} does not have to include a type suffix! The datatype can be determined by the {{Parameter|value}}.
* Constant values cannot use a variable, [[SUB]] or [[FUNCTION]] return value when defined.
* Constants cannot be re-assigned values. They retain the same value throughout all of the program procedures.
* Constants defined in module-level code have [[SHARED|shared]] scope, so they can also be used in [[SUB]] or [[FUNCTION]] procedures.
* Constants defined in {{KW|SUB}} or {{KW|FUNCTION}} procedures are local to those procedures.
* [[CLEAR]] will not affect or change constant values.
''Example:'' Display the circumference and area of circles:
{{CodeStart}}' Declare a numeric constant approximately equal to the ratio of a circle's
' circumference to its diameter:
{{Cl|CONST}} PI = 3.141593
' Declare some string constants:
{{Cl|CONST}} circumferenceText = &quot;The circumference of the circle is&quot;
{{Cl|CONST}} areaText = &quot;The area of the circle is&quot;
{{Cl|DO...LOOP|DO}}
{{Cl|INPUT}} &quot;Enter the radius of a circle or zero to quit&quot;; radius
{{Cl|IF...THEN|IF}} radius = 0 {{Cl|IF...THEN|THEN}} {{Cl|END}}
{{Cl|PRINT}} circumferenceText; 2 * PI * radius
{{Cl|PRINT}} areaText; PI * radius * radius ' radius squared
{{Cl|PRINT}}
{{Cl|DO...LOOP|LOOP}}
{{CodeEnd}}
{{OutputStart}}Enter the radius of a circle or zero to quit? ''10''
The circumference of the circle is 62.83186
The area of the circle is 314.1593
Enter the radius of a circle or zero to quit? ''123.456''
The circumference of the circle is 775.697
The area of the circle is 47882.23
Enter the radius of a circle or zero to quit? ''0''
{{OutputEnd}}
: ''Explanation:'' PI cannot change as it is a mathematical constant so it is fitting to define it as a constant. Trying to change PI will result in a programming error.
{{PageSeeAlso}}
* {{KW|DIM}}, {{KW|SHARED}}
* {{KW|STATIC}}, {{KW|COMMON}}
{{PageNavigation}}