
- •About the Author
- •Dedication
- •Author’s Acknowledgments
- •Contents at a Glance
- •Table of Contents
- •Introduction
- •Who Should Buy This Book
- •How This Book Is Organized
- •Part I: Programming a Computer
- •Part II: Learning Programming with Liberty BASIC
- •Part III: Advanced Programming with Liberty BASIC
- •Part VI: Internet Programming
- •Part VII: The Part of Tens
- •How to Use This Book
- •Foolish assumptions
- •Icons used in this book
- •Why Learn Computer Programming?
- •How Does a Computer Program Work?
- •What Do I Need to Know to Program a Computer?
- •The joy of assembly language
- •C: The portable assembler
- •High-level programming languages
- •Database programming languages
- •Scripting programming languages
- •The program’s users
- •The target computer
- •Prototyping
- •Choosing a programming language
- •Defining how the program should work
- •The Life Cycle of a Typical Program
- •The development cycle
- •The maintenance cycle
- •The upgrade cycle
- •Writing Programs in an Editor
- •Using a Compiler or an Interpreter
- •Compilers
- •Interpreters
- •P-code: A combination compiler and interpreter
- •So what do I use?
- •Squashing Bugs with a Debugger
- •Writing a Help File
- •Creating an Installation Program
- •Why Learn Liberty BASIC?
- •Liberty BASIC is easy
- •Liberty BASIC runs on Windows
- •You can start using Liberty BASIC today
- •Installing Liberty BASIC
- •Loading Liberty BASIC
- •Your First Liberty BASIC Program
- •Running a Liberty BASIC program
- •Saving a Liberty BASIC program
- •Getting Help Using Liberty BASIC
- •Exiting Liberty BASIC
- •Getting input
- •Displaying output
- •Sending Data to the Printer
- •Storing Data in Variables
- •Creating a variable
- •Assigning a value to a variable
- •Declaring your variables
- •Using Constants
- •Commenting Your Code
- •Using variables
- •Working with precedence
- •Using parentheses
- •Manipulating Strings
- •Declaring variables as strings
- •Smashing strings together
- •Counting the length of a string
- •Playing with UPPERCASE and lowercase
- •Trimming the front and back of a string
- •Inserting spaces
- •Yanking characters out of a string
- •Looking for a string inside another string
- •Using Boolean Expressions
- •Using variables in Boolean expressions
- •Using Boolean operators
- •Exploring IF THEN Statements
- •IF THEN ELSE statements
- •Working with SELECT CASE Statements
- •Checking a range of values
- •Checking a relational operator
- •Boolean expression inside the loop
- •Looping a Fixed Number of Times
- •Counting with different numbers
- •Counting in increments
- •Anatomy of a Computer Bug
- •Syntax Errors
- •Fun with Logic Errors
- •Stepping line by line
- •Tracing through your program
- •Designing a Window
- •Creating a new window
- •Defining the size and location of a window
- •Adding color to a window
- •Putting Controls in a Window
- •Creating a command button
- •Displaying text
- •Creating a check box
- •Creating a radio button
- •Creating text boxes
- •Creating list boxes
- •Creating combo boxes
- •Creating group boxes
- •Storing Stuff in Text Files
- •Creating a new text file
- •Putting stuff in a text file
- •Adding new stuff to an existing text file
- •Retrieving data from a text file
- •Creating a new binary file
- •Saving stuff in a binary file
- •Changing stuff in a binary file
- •Retrieving stuff from a binary file
- •Creating a Graphics Control
- •Using Turtle Graphics
- •Defining line thickness
- •Defining line colors
- •Drawing Circles
- •Drawing Boxes
- •Displaying Text
- •Making Sounds
- •Making a beeping noise
- •Playing WAV files
- •Passing Data by Value or by Reference
- •Using Functions
- •Defining a function
- •Passing data to a function
- •Calling a function
- •Exiting prematurely from a function
- •Using Subroutines
- •Defining a subroutine
- •Passing data to a subroutine
- •Calling a subroutine
- •Exiting prematurely from a subroutine
- •Writing Modular Programs
- •Introducing Structured Programming
- •Sequential instructions
- •Branching instructions
- •Looping instructions
- •Putting structured programming into practice
- •The Problem with Software
- •Ways to Make Programming Easier
- •Breaking Programs into Objects
- •How to use objects
- •How to create an object
- •Creating an object
- •Starting with a Pointer
- •Defining the parts of a linked list
- •Creating a linked list
- •Managing a linked list
- •Making Data Structures with Linked Lists
- •Stacks
- •Queues
- •Trees
- •Graphs
- •Creating a Record
- •Manipulating Data in Records
- •Storing data in a record
- •Retrieving data from a record
- •Using Records with Arrays
- •Making an Array
- •Making a Multidimensional Array
- •Creating Dynamic Arrays
- •Insertion Sort
- •Bubble Sort
- •Shell Sort
- •Quicksort
- •Sorting Algorithms
- •Searching Sequentially
- •Performing a Binary Search
- •Hashing
- •Searching by using a hash function
- •Dealing with collisions
- •Picking a Searching Algorithm
- •Choosing the Right Data Structure
- •Choosing the Right Algorithm
- •Put the condition most likely to be false first
- •Put the condition most likely to be true first
- •Clean out your loops
- •Use the correct data types
- •Using a Faster Language
- •Optimizing Your Compiler
- •Programming Computer Games
- •Creating Computer Animation
- •Making (And Breaking) Encryption
- •Internet Programming
- •Fighting Computer Viruses and Worms
- •Hacking for Hire
- •Participating in an Open-Source Project
- •Niche-Market Programming
- •Teaching Others about Computers
- •Selling Your Own Software
- •Trying Commercial Compilers
- •Windows programming
- •Macintosh and Palm OS programming
- •Linux programming
- •Testing the Shareware and
- •BASIC compilers
- •C/C++ and Java compilers
- •Pascal compilers
- •Using a Proprietary Language
- •HyperCard
- •Revolution
- •PowerBuilder
- •Shopping by Mail Order
- •Getting Your Hands on Source Code
- •Joining a Local User Group
- •Frequenting Usenet Newsgroups
- •Playing Core War
- •Programming a Battling Robot
- •Toying with Lego Mindstorms
- •Index
- •End-User License Agreement

Introduction
First of all, anyone can learn to program a computer. Computer programming doesn’t require a high IQ and an innate proficiency in advanced
mathematics. Computer programming just requires a desire to learn and the patience never to give up.
Programming is a skill like swimming, dancing, and juggling. Some people are naturally better than others, but anyone can get better with constant practice. That’s why so many kids become programming wizards at such an early age. The kids aren’t necessarily brilliant; they’re just willing to put in the time to learn a new skill, and they’re not afraid of failing.
If you ever dreamed about writing your own programs, rest assured that you can. Programming can be lots of fun, but it can also be frustrating, annoying, and time-consuming. That’s why Wiley publishes this particular book — to help you discover how to program a computer with the minimum amount of inconvenience and the maximum amount of enjoyment.
Whether you want to pick up computer programming for fun, to start a new career, or to help make your current job easier, consider this book your personal guide through the sometimes scary — and initially intimidating — world of computer programming.
After you finish this book, you can choose the best programming language to accomplish a particular task, understand the tools that programmers use, and even write your own programs for personal use or for sale to others.
And after you read Beginning Programming For Dummies, 3rd Edition, you
can find more detailed information about specific languages by reading Visual BASIC.NET For Windows For Dummies, by Wallace Wang; C For Dummies, by Dan Gookin; Visual C++ .NET For Dummies, by Michael Hyman and Bob Arnson; C++ For Dummies and C# For Dummies, by Stephen R. Davis;
Beginning Programming with Java For Dummies, by Barry Burd; Windows Game Programming For Dummies, by Andre LaMothe; or Perl For Dummies, by Paul Hoffman (all published by Wiley Publishing).

2Beginning Programming For Dummies, 3rd Edition
Who Should Buy This Book
Everyone should buy this book right now because you know the importance of stimulating the economy by spending as much money as possible so the current President can stay in office another four years. But you should especially buy this book if you want to know any of the following:
How to write a computer program
The best programming languages to use and why
Shortcuts for programming a computer as simply and quickly as possible
The evolution of computer programming languages
How to program a Macintosh, Palm handheld, Linux, Windows 98/Me/NT/2000/XP, or PocketPC computer
Whether to write your next computer program by using Visual BASIC, C++, Perl, SmallTalk, C#, or some other programming language
To help you start right away, this book shows you how to use a programming language by the name of Liberty BASIC, which is a shareware BASIC compiler that you can download from the Liberty BASIC Web site at www. libertybasic.com (or copy from the CD that comes with this book). By using this book and Liberty BASIC, you can start programming right away, and later, if you want, graduate to the other programming books in the popular For Dummies series.
How This Book Is Organized
This book follows the time-honored tradition of the printing industry by organizing consecutively numbered pages one after the other to form a book. To help you find what you need quickly, this book consists of seven parts, where each part covers a certain topic about programming a computer, as the following sections describe. Whenever you need help, just flip through the book, find the part that covers the topic you’re looking for, and then keep the book at your side as you get back to work.
Part I: Programming a Computer
If computer programming seems a mysterious arcane science, relax. This part of the book demystifies all the common myths about computer programming,

Introduction 3
shows you exactly how computer programs work, and explains why programming isn’t as difficult as many people think.
To help you better understand programming, this part also shows you how programming has evolved, why so many different programming languages exist, and how programming follows easy-to-remember principles so you can start programming your own computer right away.
Part II: Learning Programming with Liberty BASIC
Trying to pick up programming from a book is like trying to learn judo by reading a pamphlet. In both cases, you may glean a theoretical understanding of the subject, but until you actually practice your skill, you don’t know how much you really picked up.
To give you practical, hands-on experience in using an honest-to-goodness programming language, this part of the book explains how to install and use Liberty BASIC so that you can write real computer programs by using the BASIC programming language. Writing programs in Liberty BASIC helps you to better understand how programming really works as you work with programs and see the results right on your own computer.
Part III: Advanced Programming with Liberty BASIC
Liberty BASIC provides plenty of advanced features for displaying graphics, making sound, and debugging your programs. This part of the book shows you how to take advantage of these special features and shows you the principles behind writing programs in other languages at the same time.
Part IV: Dealing with Data Structures
As do people, computers need a place to store information. People usually dump their information in wallets, purses, filing cabinets, or garages, but computers don’t have that luxury.
Instead, computers must store information in something known as a data structure. Every computer program uses data structures, and programmers

4Beginning Programming For Dummies, 3rd Edition
invent all sorts of different data structures for various uses. So in this part of the book, I explain how every program uses data structures and provide hands-on examples you can try using Liberty BASIC.
Part V: Algorithms: Telling the
Computer What to Do
Algorithms are a fancy way of telling a computer how to accomplish a specific task, step-by-step. Think of an algorithm as a recipe that the computer blindly follows without question.
One perfect algorithm doesn’t exist for writing all computer programs, just as one perfect recipe doesn’t exist for making all dinners. To make programming easier, programmers invent common algorithms for accomplishing certain tasks. This part of the book explains how those algorithms work and why you want to use them.
Part VI: Internet Programming
The Internet is an integral part of the computer world, so this part of the book introduces you to the basics of various Internet languages, including HTML (which designs the appearance of Web pages), JavaScript, and Java.
In this part, you also see how other people create cool Web pages that look good and can display forms and respond to users. You can use this information to create Web sites that interact with users.
Part VII: The Part of Tens
To help gently guide you toward writing your own programs, this part of the book provides information that you may find useful to take your programming education a step farther.
This part is where the book shows you many of the opportunities that a career in programming can offer. In this part, too, you discover where to find and use various free or commercial programming languages available on the Internet or on this book’s enclosed CD. Many of these programming languages sport common names such as C++ and BASIC — or bizarre names such as LISP, Oberon, and Python.