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›Conditions (IF / DO CASE)

Conditions (IF / DO CASE)

Decision making with IF-ELSE and multi-way selection with DO CASE.

Simple enough for a 5-year-old to understand

IF / ELSE

Example code
1
LOCAL number := 7
2
IF number % 2 == 0
Is the remainder zero?
ConditionIs the remainder zero?
3
QOut("even")
If the condition is true.
Output / InputIf the condition is true.
4
ELSE
5
QOut("odd")
If the condition is false.
Output / InputIf the condition is false.
6
ENDIF
The block ends here.
ConditionThe block ends here.
ConditionOutput / Input
💡 Hint: It is safest to use a double equals sign in comparisons.

🎯 Exercise & Practice

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

1.Which keyword closes an IF block?

About this topic

In Clipper, conditions start with if and close with their own closing keyword. There is a separate keyword for chained branches, and no matter how many branches are inside a condition block, a single ending is enough.

Boolean values are written with letters enclosed between dots, and logical operators follow the same format. This syntax is unique to the xBase family and looks foreign at first glance.

There is a switch structure for multi-branch decisions. Unlike its counterparts in other languages, each branch can contain a conditional expression, not just having to match a fixed value; this provides a flexible way to flatten long condition chains.

What you will learn

  • Condition block structure
  • Logical value and operator syntax
  • The switch structure
  • The function returning a conditional value
  • Checks for blankness and absence of value

Who is this for?

  • Those writing decision logic in Clipper code
  • Those getting used to xBase syntax
  • Those fixing old reports

When to use?

For decisions with more than three branches, the switch structure is significantly more legible than nested conditions and gives the flexibility to write a separate condition for each branch.

When you need to choose one of two values in a single line, the conditional value function is used; it shortens the code since it can be written on the right side of the assignment.

Common mistakes

Wrong

PROCEDURE Main()
   LOCAL yas := 20
   IF yas >= 18
      ? "adult"
   ELSE IF yas >= 13
      ? "teen"
   ENDIF
   RETURN

The chained branch is written as a single word; when written as two words, this starts a new and separate condition block and requires its own ending. The compiler throws an error due to a missing ending. Two seemingly similar spellings carry completely different meanings.

Correct

PROCEDURE Main()
   LOCAL yas := 20
   IF yas >= 18
      ? "adult"
   ELSEIF yas >= 13
      ? "teen"
   ENDIF
   RETURN

Wrong

PROCEDURE Main()
   LOCAL aktif := TRUE
   IF aktif
      ? "open"
   ENDIF
   RETURN

In Clipper, the boolean true value is written with a single letter enclosed between dots; a naked word is considered an undefined variable and carries an absence of value. The condition throws a type mismatch error in this case. The spelling of boolean constants is language-specific.

Correct

PROCEDURE Main()
   LOCAL aktif := .T.
   IF aktif
      ? "open"
   ENDIF
   RETURN

Wrong

PROCEDURE Main()
   LOCAL a := 5, b := 2
   IF a > 1 && b < 3
      ? "okay"
   ENDIF
   RETURN

A double ampersand starts an end-of-line comment in Clipper; the rest of the condition is considered a comment and the expression remains incomplete. The format enclosed between dots must be used for the logical and operation. Two similar signs having completely different meanings produce confusing errors in legacy code.

Correct

PROCEDURE Main()
   LOCAL a := 5, b := 2
   IF a > 1 .AND. b < 3
      ? "okay"
   ENDIF
   RETURN

Frequently asked questions

How does the switch structure work?

Each branch carries its own conditional expression; the first true branch from top to bottom executes and the structure ends. A final branch can be defined to run if none are true. There is no obligation to match a fixed value.

How is a blankness check performed?

There is a single function that tells whether a value is blank, and it works on all types: it returns true for empty text, zero, empty date, and empty array. Since it is type-independent, it is the standard way to test data file fields.

When is the conditional value function used?

When you need to choose between two values and use them inside an expression. Since it is a function, both values are evaluated; side-effect or costly calls should not be placed inside this function.

Summary

The chained branch is written as a single word.

Boolean constants are enclosed between dots.

Double ampersands start a comment.

In the switch structure, each branch can carry a condition.

Blankness checks are done on all types with a single 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