BeginningProgrammingforDummies,4th
Edition
byWallaceWang
JohnWiley&Sons2007(408pages)
ISBN:9780470088708
Offeringnewtechniquesthatwillmakeprogramming
easierandmorefun,thisbookwillteachyouenough
aboutprogrammingtohelpyouunderstandhow
programmingworksandhowyoucangetstarted
writingprogramsallbyyourself.
TableofContents
BeginningProgrammingforDummies,4thEdition
Introduction
CheatSheet
PartI-ProgrammingaComputer
PartOverview
Chapter1 - LearningComputerProgrammingforthe
FirstTime
Chapter2 - AllAboutProgrammingLanguages
Chapter3 - HowtoWriteaProgram
Chapter4 - TheToolsofaComputerProgrammer
PartII-TheBuildingBlocksofProgramming
PartOverview
Chapter5 - GettingStarted
Chapter6 - TheStructureofaComputerProgram
Chapter7 - Variables,Constants,andComments
Chapter8 - CrunchingNumbersandPlayingwith
Strings
Chapter9
- MakingDecisionswithBranching
Statements
Chapter10 - RepeatingYourselfwithLoops
Chapter11 - DividingaProgramintoSubprograms
Chapter12 - StoringStuffinArrays
Chapter13 - PlayingwithObject-Oriented
Programming
PartIII-AdvancedProgrammingTopics
PartOverview
Chapter14 - SortingandSearchingAlgorithms
Chapter15 - DebuggingPrograms
Chapter16 - OptimizingYourCode
Chapter17 - CreatingaUserInterface
PartIV-InternetProgramming
PartOverview
Chapter18 - PlayingwithHTML
Chapter19 - MakingInteractiveWebPageswith
JavaScript
Chapter20 - UsingJavaAppletsonWebPages
PartV-ThePartofTens
PartOverview
Chapter21 - TenAdditionalProgrammingResources
Chapter22 - TenCoolProgrammingCareers
AppendixA - CommonLoopandBranchingStructures
AppendixB - FreeLanguageCompilersand
Interpreters
AppendixC - CommonProgrammingTerms
AppendixD - InstallingtheCDCompilers
Index
ListofFigures
ListofTables
ListofListings
ListofSidebars
BackCover
Newtechniquesmakeprogrammingeasierandmore
fun
Discoverprinciplesandbestpracticesthatletyou
programinmanylanguages
Soyoualwaysthoughtprogrammersweresuperior
beingsfromanothergalaxy?Surprise!Programming
isn'tallthatdifficultwhenyouknowhow.Here'sthe
funandeasyroutetowritingprogramsthatwork
efficientlyforWindows,MacOSX,orLinux,
understandingbasicprogrammingprinciples,using
differentlanguages,programmingfortheInternet,and
muchmore.
Discoverhowto
Writeprogramsformultipleplatforms
ProgramusingBASICandC++
Recognizesimilaritiesindifferentprogramming
languages
UseRevolution,anon-traditionallanguage
Fine-tuneanddebugprograms
BeginningProgrammingforDummies,4th
Edition
WallaceWang
WileyPublishing,Inc.
Publishedby
WileyPublishing,Inc.
111RiverStreet
Hoboken,NJ07030-5774
www.wiley.com
©2007byWileyPublishing,Inc.,Indianapolis,Indiana
ISBN0470088702
PublishedbyWileyPublishing,Inc.,Indianapolis,Indiana
PublishedsimultaneouslyinCanada
Nopartofthispublicationmaybereproduced,storedinaretrieval
systemortransmittedinanyformorbyanymeans,electronic,
mechanical,photocopying,recording,scanningorotherwise,exceptas
permittedunderSections107or108ofthe1976UnitedStatesCopyright
Act,withouteitherthepriorwrittenpermissionofthePublisher,or
authorizationthroughpaymentoftheappropriateper-copyfeetothe
CopyrightClearanceCenter,222RosewoodDrive,Danvers,MA01923,
(978)750-8400,fax(978)646-8600.RequeststothePublisherfor
permissionshouldbeaddressedtotheLegalDepartment,Wiley
Publishing,Inc.,10475CrosspointBlvd.,Indianapolis,IN46256,(317)
572-3447,fax(317)572-4355,oronlineat
/>
Trademarks:Wiley,theWileyPublishinglogo,ForDummies,the
DummiesManlogo,AReferencefortheRestofUs!,TheDummiesWay,
DummiesDaily,TheFunandEasyWay,Dummies.com,andrelated
tradedressaretrademarksorregisteredtrademarksofJohnWiley&
Sons,Inc.and/oritsaffiliatesintheUnitedStatesandothercountries,
andmaynotbeusedwithoutwrittenpermission.Allothertrademarksare
thepropertyoftheirrespectiveowners.WileyPublishing,Inc.,isnot
associatedwithanyproductorvendormentionedinthisbook.
LIMITOFLIABILITY/DISCLAIMEROFWARRANTY:THEPUBLISHER
ANDTHEAUTHORMAKENOREPRESENTATIONSOR
WARRANTIESWITHRESPECTTOTHEACCURACYOR
COMPLETENESSOFTHECONTENTSOFTHISWORKAND
SPECIFICALLYDISCLAIMALLWARRANTIES,INCLUDINGWITHOUT
LIMITATIONWARRANTIESOFFITNESSFORAPARTICULAR
PURPOSE.NOWARRANTYMAYBECREATEDOREXTENDEDBY
SALESORPROMOTIONALMATERIALS.THEADVICEAND
STRATEGIESCONTAINEDHEREINMAYNOTBESUITABLEFOR
EVERYSITUATION.THISWORKISSOLDWITHTHE
UNDERSTANDINGTHATTHEPUBLISHERISNOTENGAGEDIN
RENDERINGLEGAL,ACCOUNTING,OROTHERPROFESSIONAL
SERVICES.IFPROFESSIONALASSISTANCEISREQUIRED,THE
SERVICESOFACOMPETENTPROFESSIONALPERSONSHOULD
BESOUGHT.NEITHERTHEPUBLISHERNORTHEAUTHORSHALL
BELIABLEFORDAMAGESARISINGHEREFROM.THEFACTTHAT
ANORGANIZATIONORWEBSITEISREFERREDTOINTHISWORK
ASACITATIONAND/ORAPOTENTIALSOURCEOFFURTHER
INFORMATIONDOESNOTMEANTHATTHEAUTHORORTHE
PUBLISHERENDORSESTHEINFORMATIONTHEORGANIZATION
ORWEBSITEMAYPROVIDEORRECOMMENDATIONSITMAY
MAKE.FURTHER,READERSSHOULDBEAWARETHATINTERNET
WEBSITESLISTEDINTHISWORKMAYHAVECHANGEDOR
DISAPPEAREDBETWEENWHENTHISWORKWASWRITTENAND
WHENITISREAD.
Forgeneralinformationonourotherproductsandservices,please
contactourCustomerCareDepartmentwithintheU.S.at800-762-2974,
outsidetheU.S.at317-572-3993,orfax317-572-4002.
Fortechnicalsupport,pleasevisitwww.wiley.com/techsupport.
Wileyalsopublishesitsbooksinavarietyofelectronicformats.Some
contentthatappearsinprintmaynotbeavailableinelectronicbooks.
LibraryofCongressControlNumber:2006932692
ISBN-13:978-0-470-08870-8
ManufacturedintheUnitedStatesofAmerica
10987654321
4O/RW/RQ/QW/IN
Dedication
ThisbookisdedicatedtoallthewonderfulpeopleI’vemetalongthepath
oflife,including…
Cassandra(mywife),Jordan(myson),andBo,Scraps,Tasha,andNuit
(ourcats).
LilyCarnie,theonlypersonIknowwhocantrulyseebothsidesofthe
story.
AllthefriendlyfolksI’vemetwhileperformingattheRivieraComedy
Club,locatedattheRivieraHotel&CasinoinLasVegas:SteveSchirripa
(whoalsoappearsontheHBOshow,TheSopranos,whichyoucanread
aboutatwww.hbo.com/sopranos),DonLearned,BobZany,Gerry
Bednob,BruceClark,DarrellJoyce,andKipAddotta.Thenexttime
you’revisitingLasVegas,dropbytheRivieraandwatchacomedyshow.
Thendumpsomemoneyinaslotmachineonthewayouttoensurethat
theRivieraHotel&Casinocontinuesmakingenoughmoneytokeepits
comedyclubopen.
ThanksalsogotoRogerFeenyattheAnnArborComedyShowcasein
AnnArbor,Michigan;RussRivasatLaff’sinAlbuquerque,NewMexico;
PatWilsonatMesquite,Nevada;andJoeJarredatPrimmandPahrump,
Nevadaforrunningsomeofthefriendliestcomedyclubsaroundthe
country.
FinalthanksmustalsogotoLeo(theman,themyth,thelegend)
Fontaine,Chris(theZooman)Clobber,RickGene,WesSample,Justin
Davis,andDante(whogetsexcitedjusttoseehisnameinabook).
AbouttheAuthor
WallaceWangisoneofmanycarbon-basedlifeformscurrently
populatingtheplanetEarth.Hebeganhisworkingcareerbygoingto
collegeandgettinga“good”job-onlytofindthatacollegeeducation
neverguaranteedyoua“good”jobandmost“good”jobsactuallystink.
Sofacedwiththeprospectofspendingtherestofhiswakinglifeina
caffeine-inducedstuporcoupledwithshotsofalcoholandgamblingto
dullthefrustrationofadead-endjob,hedecidedtopursueoneofmany
dreamsbybecomingawriter.Firststartingoutwritingmagazinearticles
foralocalSanDiegocomputermagazine,hesoongraduatedtowriting
fornationalpublicationsandbookpublishersaswell.
Afternearly20yearsofwritingfull-time,he’sstillpursuingavarietyof
differentdreamsbesidescontinuingbookandmagazinewriting.He’sstill
bouncingaroundcomedyclubsaroundMichigan,LasVegas,andSan
Diego,performingstand-upcomedytoanyonesoberenoughtolisten.
He’salsobranchedawayfromcomputerbooksbyteamingupwith
coauthorstowritenon-computerrelatedbooks,mostnotablyBreaking
IntoActingForDummieswithLarryGarrison.(ThanksgotoBenAffleck
forcarryingaroundacopyandgettinghispicturetakenwiththebook,
whichappearedinmanymajormagazinesincludingPeopleMagazine
andTheNewYorkPost.)
Inhislatestmadventuretoavoidhavingtoworkinanordinary9–5job,
he’salsoteamedupwiththreeothercomedians(RickGene,Wes
Sample,andJustinDavis)tocreate,produce,andhostaradioshow
called“KeepingItWeird,”currently(atleastatthetimeofthiswriting)
airingon103.7FreeFMinSanDiego.
Bythetimeyoureadthis,theauthormaybeoffpursuingsomething
entirelydifferent.Whateverhemaybedoingatthetime,itshouldatleast
makeforinterestingstoriestotellhisgrandchildrenaboutoneday.
Author’sAcknowledgments
Ifitwasn’tforBillGladstoneatWatersideProductions,Imightstillbe
staringoffintospaceinacubiclesomewhere,workinginadead-endjob,
wonderingwhatcouldhavebeen.
AdditionalthanksgotoAllenWyattformakingsurethateverythinginthis
bookisaccurate,alongwithRebeccaSenningerandVirginiaSandersfor
makingtheprocessofwritingabookalwayspainless,easy,andoften
fun.
FinalacknowledgementsgotoCassandra(mywife)forputtingupwith
multiplecomputersthat(fromherpointofview)seemtospontaneously
appearanddisappeararoundthehouseatrandom.Eachtimea
computerdisappears,amoreadvancedmodelappearsthatpromises
morespeedandharddrivespace,butstillneverseemstohavemore
speedorasmuchroomasthepreviouscomputermodelthatitreplaced.
Publisher’sAcknowledgments
We’reproudofthisbook;pleasesendusyourcommentsthroughour
onlineregistrationformlocatedatwww.dummies.com/register/.
Someofthepeoplewhohelpedbringthisbooktomarketincludethe
following:
Acquisitions,Editorial,andMediaDevelopment
ProjectEditor:RebeccaSenninger
(PreviousEdition:AndreaC.Boucher)
AcquisitionsEditor:KatieFeltman
CopyEditor:VirginiaSanders
TechnicalEditor:AllenWyatt
EditorialManager:LeahCameron
MediaDevelopmentSpecialists:AngelaDenny,KateJenkins,
StevenKudirka,KitMalone
MediaDevelopmentCoordinator:LauraAtkinson
MediaProjectSupervisor:LauraMoss
MediaDevelopmentManager:LauraVanWinkle
EditorialAssistant:AmandaFoxworth
Sr.EditorialAssistant:CherieCase
Cartoons:RichTennant(www.the5thwave.com)
CompositionServices
ProjectCoordinator:MichaelKruzil
LayoutandGraphics:ClaudiaBell,CarlByers,BrookeGraczyk,
DennyHager,JoyceHaughey,StephanieD.Jumper,Barbara
Moore,BarryOffringa,LauraPence,AliciaSouth
Proofreaders:LauraAlbert,Techbooks
Indexer:SteveRath
AnniversaryLogoDesign:RichardPacifico
PublishingandEditorialforTechnologyDummies
RichardSwadley,VicePresidentandExecutiveGroupPublisher
AndyCummings,VicePresidentandPublisher
MaryBednarek,ExecutiveAcquisitionsDirector
MaryC.Corder,EditorialDirector
PublishingforConsumerDummies
DianeGravesSteele,VicePresidentandPublisher
JoycePepple,AcquisitionsDirector
CompositionServices
GerryFahey,VicePresidentofProductionServices
DebbieStailey,DirectorofCompositionServices
Introduction
Overview
Anyonecanlearntoprogramacomputer.Computerprogramming
doesn’trequireahighIQoraninnateproficiencyinadvanced
mathematics.Computerprogrammingjustrequiresadesiretolearnand
thepatiencenevertogiveup.
Programmingisaskilllikerockclimbing,tapdancing,andpolevaulting.
Somepeoplearenaturallybetterthanothers,butanyonecangetbetter
withregularpractice.That’swhysomanykidsbecomeprogramming
wizardsatsuchanearlyage.Thesekidsaren’tnecessarilybrilliant;
they’rejustwillingtoputinthetimetolearnanewskill,andthey’renot
afraidoffailingbecausetheyknowthatfailureisnothingmorethanapart
oflearning.
Ifyoueverdreamedaboutwritingyourownprograms,restassuredthat
youcan.Programmingcanbelotsoffun,butitcanalsobefrustrating,
annoying,andtime-consuming.That’swhyWileypublishesthisparticular
book-tohelpyoudiscoverhowtoprogramacomputerwithminimum
inconvenienceandmaximumenjoyment.
Whetheryouwanttopickupcomputerprogrammingforfun,tostarta
newcareer,ortohelpmakeyourcurrentjobeasier,considerthisbook
yourpersonalguidethroughthesometimesscary-andinitially
intimidating-worldofcomputerprogramming.
Althoughthisbookwon’tturnyouintoaprogrammingwizardovernight,it
canteachyouenoughaboutprogrammingtohelpyouunderstandhow
programmingworks,whatthestrengthsandweaknessesofdifferent
programminglanguagesare,andhowyoucangetstartedwriting
programsallbyyourself.
WhoShouldBuyThisBook
Youshouldbuythisbookifyouwanttolearnhowcomputerprogramming
workswithoutgettingboggeddowninthetechnicaldetailsofaparticular
programminglanguage.Whenyouunderstandhowcomputer
programmingworks,you’llbetterunderstandhowtouseaspecific
programminglanguagewithcrypticnameslikeC++orJava.Butyou
shouldbuythisbookifyouespeciallywanttoknowanyofthefollowing:
Howcomputerprogramswork
Thecommonpartsofeverycomputerprogramminglanguage
HowtowriteprogramsformultipleplatformssuchasWindows,
MacOSX,orLinux
WhethertowriteyournextcomputerprogrambyusingVisual
Basic,C++,Perl,SmallTalk,C#,orsomeotherprogramming
language
Likeanyskill,youcanlearnprogrammingonlybypracticingit.Tohelp
yougethands-onexperience,theCDenclosedwiththisbookincludes
trialversionsoffourlanguagecompilerssoyoucanpracticewriting
programsonanycomputerthatrunsWindows,MacOSX,orLinux.
ThethreemainlanguagesyoulearninthisbookareBASIC,C++,anda
scriptinglanguagecalledRevolution.
BASICisspeciallydesignedtointroducebeginnerstoprogramming,so
youcanpracticewritingBASICprogramsintwoprogramminglanguages:
LibertyBASICandREALbasic.
LibertyBASICrepresentstheBASIClanguageinitspurestandsimplest
formsoyoucanunderstandtheconceptsofprogrammingwithoutgetting
lostinthetechnicaldetails.WhenyouunderstandhowBASICworks,you
canstudyREALbasictoseeaversionoftheBASIClanguagethat
includesadvancedprogrammingfeaturessimilartomorepowerful
languagessuchasC++.
ThisbookalsoprovidesexamplesinC++,whichisthemostpopular
programminglanguageinusetoday.Ifyouwanttowriteprograms
professionally,youmustatleastbecomefamiliarwiththewayC++
works.
YoualsolearnanontraditionalprogramminglanguagecalledRevolution,
whichusesEnglish-likesentencestocontrolyourcomputer.Scripting
languageslikeRevolutionaredesignedtobeeasytowriteand
understand.Theyalsoprovidecommandscapableofsolvingcomplicated
problemsmoreeasilythantraditionalprogramminglanguageslikeBASIC
orC++.
Inaddition,theRevolutionprogramminglanguageisbasedon
AppleScript,whichisaprogramminglanguageusedtoautomateaMac
OSXcomputer,soafteryou’refamiliarwithRevolution,youalsoknow
mostoftheAppleScriptprogramminglanguage.
BylearningBASIC,C++,andRevolution,you’reexposedtothree
differentprogramminglanguages,styles,andapproachestosolving
problemssoyoucanbetterunderstandtheadvantagesandlimitationsof
anyprogramminglanguage.Thenyoucanchoosethebestprogramming
languageforyourneeds.
HowThisBookIsOrganized
Tohelpyoufindwhatyouneedquickly,thisbookconsistsoffiveparts,
andeachpartcoversacertaintopicaboutcomputerprogramming.
Wheneveryouneedhelp,justflipthroughthebook,findthepartthat
coversthetopicyou’relookingfor,andthenkeepthebookatyourside
asyougetbacktowork.
PartI:ProgrammingaComputer
Ifcomputerprogrammingseemsamysteriousarcanescience,relax.This
partofthebookdemystifiesallthecommonmythsaboutcomputer
programming,showsyouexactlyhowcomputerprogramswork,and
explainswhyprogrammingisn’tasdifficultasmanypeoplethink.
Thispartalsoshowsyouhowprogramminghasevolved,whysomany
differentprogramminglanguagesexist,andhowprogrammingfollows
easy-to-rememberprinciplessoyoucanstartprogrammingyourown
computerrightaway.
PartII:TheBuildingBlocksofProgramming
Althoughliterallythousandsofdifferentprogramminglanguagesare
availableforyoutolearn,everyprogramminglanguagetendstoworkin
similarways.Sointhispartofthebook,youlearnthebasicbuilding
blocksofwritingandcreatingaprogramregardlessoftheparticular
programminglanguageyouuse.
Tohelpyouunderstandthebuildingblocksofprogramming,eachchapter
providesplentyofexamplesindifferentprogramminglanguagessoyou
canseehowtheyaccomplishthesametask.Youcanalsotryoutthe
examplesonyourowncomputer.
PartIII:AdvancedProgrammingTopics
Afteryoumasterthebasicsofwritingaprogram,youneedtoworryabout
makingyourprogramworkefficiently,eliminatingproblems,and
designingauserinterfacesootherpeoplewillknowhowtouseit.Inthis
partofthebook,youlearnhowprogrammersfine-tunetheirsoftware
(andwhattheconsequencesmightbeiftheydon’t).
PartIV:InternetProgramming
TheInternetisfastbecominganintegralpartofthecomputerworld,so
thispartofthebookintroducesyoutothebasicsofvariousInternet
languages,includingHTML(whichdesignstheappearanceofWeb
pages),JavaScript,andJava.
Inthispart,youalsoseehowotherpeoplecreatecoolWebpagesthat
lookgoodandcandisplayformsandrespondtousers.Youcanusethis
informationtocreateWebsitesthatinteractwithusers.
PartV:ThePartofTens
Tohelpgentlyguideyoutowardwritingyourownprogramsformoney,
thispartofthebookprovidesinformationaboutprogrammingjobsyou
mightwanttopursueandhowtofindmoretoolsandsourcecodetohelp
youlearnmoreaboutprogrammingallbyyourself.
HowtoUseThisBook
Thisbookismeanttoshowyouthebasicsofcomputerprogramming
withoutboggingyoudownwiththetechnicaldetailsofanyparticular
programminglanguage.Typedcodeoftenlookslikechickenscratchesor
therandomcharactersthatamonkeymighttypeifleftalonewitha
keyboard.Soyoucanusethisbookasatutorial(toshowyouhow
programmingworks)andasareference(tohelprefreshyourmemoryfor
understandingdifferentprogrammingtechniques).
Ideally,youwanttousethisbookalongwithyourcomputer.Readsome
ofthebookandthentrywhatyoujustreadonyourcomputersothatyou
canseewithyourowneyeshowprogrammingworks.
Foolishassumptions
Togetthemostoutofthisbook,youneedaccesstoacomputer
(becausetryingtounderstandcomputerprogrammingwithouta
computerisliketryingtolearntodrivewithoutacar).Totakefull
advantageofthisbook,youneedacomputerrunningMicrosoft
Windows,MacOSX,orLinux.
Iconsusedinthisbook
Iconshighlightusefultips,importantinformationtoremember,or
technicalexplanationsthatcanamuseyouforamomentbeforeyou
forgetallaboutthem.Keepaneyeopenforthefollowingicons
throughoutthebook:
TipThisiconhighlightsusefulinformationthatcansaveyoutime(as
longasyourememberit,ofcourse).
RememberThisiconremindsyoutodosomethingoremphasizesan
importantpointthatyoudon’twanttoforget.
Warning!Watchout!Thisicontellsyouhowtoavoidpotential
headachesandtrouble.
OntheCDThisiconidentifiesthenameofaparticularfileontheCDthat
containsasampleprogramprintedinthebook.Byloadingthesample
programofftheCD,youdon’thavetotypetheprogramyourself.
TechnicalStuffThisiconhighlightsinformationthat’snicetoknowbut
whichyoucansafelyignoreifyouchoose.(Ifyouwanttobecomeareal
programmer,however,youneedtocramyourbrainwithasmuch
technicalinformationaspossiblesothatyoucanfitinwiththerestofthe
programmersintheworld.)
CheatSheet
TipsforWritingPrograms
Usedescriptivevariablenames.
Useappropriatedatatypes.
Writeprogramsthatareeasytoreadandunderstand.
Usesimplealgorithmsanddatastructureswheneverpossible.
Commentyourprogramliberally.(Or,asanalternative,make
yourcodesoclearandeasytoreadthatyoudon’tneed
commentsinthefirstplace.)
Writemodularprogramsbydividingalargeprograminto
severalsmallerprogramsthatyouisolatefromoneanother.
Testboundaryconditionsbygivingyourprogramextremely
highandextremelylownumbers.
Choosetherightalgorithmanddatastructureforyour
program.
Eliminateallunnecessaryinstructionsorvariables.
Makeyourprogramworkfirst;thenworryaboutoptimizingthe
programtomakeitsmallerandfaster.Rememberthataslow,
bloatedprogramthatworksispreferabletoasmall,fastprogram
thatdoesn’twork.
CommonLoopStructures
SeeAppendixAformoreloopstructures.
Opentableasspreadsheet
LibertyBASIC
REALbasic
WHILEcondition
Instructions
WEND
WHILEcondition
Instructions
WEND
FORi=StartTOEnd
Instructions
NEXTi
FORi=StartTOEnd
Instructions
NEXT
C++
Revolution
while(condition)
{
Instructions
}
repeatwhilecondition
Instructions
endrepeat
for(initial;conditional;incr) repeatwithi=Start
{
Instructions
Instructions
endrepeat
}
CommonMathematicalOperators
Opentableasspreadsheet
Mathematical
Operation
Symbolto
Use
Mathematical
Operation
Symbolto
Use
Addition
+
Modulo
mod
Subtraction
–
Multiplication
*
Division
/(forward
slash)
Exponentiation
^
Integerdivision
\(backward
slash)
CommonBranchingStructures
SeeAppendixAformorebranchingstructures.
Opentableasspreadsheet
LibertyBASIC
REALbasic
IFconditionTHEN
Instructions
ENDIF
IFconditionTHEN
Instructions
ENDIF
IFconditionTHEN
Instructions
ELSE
Instructions
ENDIF
IFconditionTHEN
Instructions
ELSE
Instructions
ENDIF
SELECTCASEvariable
CASEvalue1
Instructions
CASEvalue2
Instructions
ENDSELECT
SELECTCASEvariable
CASEvalue1
Instructions
CASEvalue2
Instructions
ENDSELECT
SELECTCASEvariable
SELECTCASEvariable
CASEvalue1,value2,value3CASEvalue1,value2,value3
Instructions
Instructions
CASEvalue4,value5,value6CASEvalue4TOvalue5
Instructions
Instructions
ENDSELECT
ENDSELECT
C++
Revolution
if(condition)
{
Instructions
ifconditionthen
Instructions
else
}
else
{
instructions
}
instructions
endif
switch(variable)
{
casevalue1:
instructions
break;
casevalue2:
instructions
break;
default
instructions
}
switchvariable
casevalue1:
instructions
break;
casevalue2:
instructions
break;
default
instructions
endswitch
switch(variable)
{
casevalue1:
casevalue2:
casevalue3:
instructions
break;
casevalue4:
casevalue5:
casevalue6:
instructions
break;
default
instructions
}
switchvariable
casevalue1:
casevalue2:
casevalue3:
instructions
break;
casevalue4:
casevalue5:
casevalue6:
instructions
break;
default
instructions
endswitch