HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to ClipperVariablesStringsConditions (IF / DO CASE)Loops (FOR / DO WHILE)DBF Database
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ Text & Number
🔁 Condition & Loop
🗃️ Functions & Database
Clipper›Variables

Variables

Defining variables with LOCAL, assignment, and scope types.

Simple enough for a 5-year-old to understand

Define with LOCAL

Variables are usually defined with LOCAL. Assignment is done with a colon and an equals sign.

Example code
1
LOCAL name
Defines the variable.
VariableDefines the variable.
2
name := "Alex"
The assignment operator is a colon and equals sign.
VariableThe assignment operator is a colon and equals sign.
3
QOut(name)
Alex writes.
Output / InputAlex writes.
VariableOutput / Input
💡 Hint: In assignment, a colon and equals sign are used instead of a single equals sign.

The value can change

Example code
1
LOCAL score
2
score := 10
Initial value.
VariableInitial value.
3
score := 20
New value.
VariableNew value.
4
QOut(score)
Writes 20.
Output / InputWrites 20.
VariableOutput / Input

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Which is the assignment operator in Clipper?

About this topic

Variables in Clipper are used without type declarations; a variable can hold a number, text, date, logical value, or array. The type is determined by the value and can change at runtime.

What is critical is scope, not type. There are four scope keywords in Clipper, and the default behavior is the most dangerous: an undeclared variable has dynamic scope, meaning it is also visible inside procedures you call.

This dynamic scope is the most error-prone feature of the xBase family. When the same name is used in two different places, one silently overwrites the other's value. Declaring every variable as local is the most valuable improvement you can make in Clipper code.

What you will learn

  • Scope keywords
  • The importance of local declaration
  • Distinguishing assignment from comparison
  • Dynamic typing
  • Checking for the absence of a value

Who is this for?

  • Those inheriting Clipper code
  • Those dealing with unexpected value changes
  • Those untangling scope confusion

When to use?

In every newly written procedure, all variables must be declared locally; this completely eliminates conflicts caused by dynamic scope.

Static scope is used for counter and cache variables that need to maintain their values between calls, while public scope is only appropriate for settings that truly need to be accessed from anywhere in the program.

Common mistakes

Wrong

PROCEDURE Main()
   sayac := 0
   Artir()
   ? sayac
   RETURN

PROCEDURE Artir()
   sayac := 99
   RETURN

Since the variable is not declared, it gets dynamic scope, and the called procedure sees and modifies the same variable; ninety-nine is printed on the screen. The two procedures are thought to be independent while silently sharing the same data. Local declaration cuts this tie.

Correct

PROCEDURE Main()
   LOCAL sayac := 0
   Artir()
   ? sayac
   RETURN

PROCEDURE Artir()
   LOCAL sayac := 99
   RETURN

Wrong

PROCEDURE Main()
   LOCAL a := 5
   LOCAL b
   b = 10
   ? a, b
   RETURN

A single equals sign is the comparison operator within expressions; a colon and an equals sign are used for assignment. Since a single equals sign also acts like an assignment in some contexts, the behavior is inconsistent. In new code, the explicit assignment operator should always be written.

Correct

PROCEDURE Main()
   LOCAL a := 5
   LOCAL b
   b := 10
   ? a, b
   RETURN

Wrong

PROCEDURE Main()
   LOCAL deger
   IF deger = 0
      ? "zero"
   ENDIF
   RETURN

A variable that is declared but not assigned a value carries the absence of a value; comparing this to a number produces a type mismatch error. To check if a variable is empty, a separate function must be used or an initial value must be provided upon declaration.

Correct

PROCEDURE Main()
   LOCAL deger := 0
   IF deger == 0
      ? "zero"
   ENDIF
   RETURN

Frequently asked questions

What is the difference between the four scopes?

Local scope is only visible in that procedure and is the safest. Static scope retains its value between calls. Dynamic scope is also visible in called procedures. Public scope is accessible from anywhere in the program.

Can I find out the type of a variable?

Yes, there is a function that returns the type of a value as a single letter. In a dynamically typed language, especially with values coming from a data file or user, checking the type before performing operations prevents errors.

How are arrays defined?

By providing the size in the declaration or by directly writing a list of values with curly braces. Arrays are one-indexed and their size can be expanded at runtime; this flexibility is one of the most important innovations brought by Clipper 5.

Summary

Variables are used without type declarations.

Undeclared variables get dynamic scope.

Every variable must be declared locally.

Assignment is done with a colon and an equals sign.

The absence of a value is checked with a separate function.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code