Action! › and› BBS Express! PRO› Tutorial›› by› Thomas M. Johnson ››› Available from ›› Villa Video's Bargain Cellar › (414) 265-5149 › ExpressNet Node X11 ››Action! is copyright of ACS, OSS, ICD.›BBS Express! PRO is copyright Orion›Micro Systems.› ›This tutorial is copyright Thomas M.›Johnson.››This tutorial can be distributed under›the following conditions:› 1) It is free.› 2) All of the above› information is intact.››--------------------------------------››Well, I guess its time we started›talking about loops. Loops give us›the ability to repeat a section of›code over and over again until›we want it to stop.››The section of code we want to repeat›is marked off with a DO at the start›and a OD at the end.›› PROC main()›› DO› Print("Hello!! ")› OD› RETURN››This is print Hello!! over and over›and there is no way to stop it other›than pressing the BREAK key or›the RESET key. So we need a way›to control the number of times›a loop get executed. Action!›provides us with 3 ways.››The first and probably the least›powerful is the FOR loop. It is the›most used loop. Then why do I say›it is the least powerful? Because›it executes a loop a fixed number of›times.›› PROC main()›› BYTE i›› FOR i=1 TO 8› DO› PrintBE(i)› OD› › RETURN››This program just prints the numbers›1 to 8 vertically on the screen. ANY›commands can be places between the›DO and the OD and they will get›executed 8 times.››The next loop controller Action!›gives us it the WHILE loop. It looks›like this:›› WHILE (a condition is true)› DO›› OD››The WHILE loop evaluates its ›condition at the top of the loop, so›if the condition is FALSE to begin›with, the loop will never execute.›Try program APROG.401 to see.››The last type of loop control Action!›gives us is the UNTIL loop.›› DO› statements› UNTIL (condition is true)› OD››The major difference between the WHILE›and the UNTIL is that the UNTIL get›evaluated at the bottom of the loop.›This means it will be executed at›once. After it is executed once, if›the condition is FALSE it will get›executed again.›› DO› PutE()› PrintE("Press any key or 0")› PrintE("to exit")› i=InputB()› UNTIL i=0› OD››If the condition i=0 is TRUE the loop›exits.››The last loop command I saved for last›to mention because in theory, it is›never needed. I say in theory because›in the REAL world it can be useful.››The command name is EXIT. Lets›say your program has to input a›large number. And the next numbers›are divided into the bug number›until the answer gets down below›10. But if the user inputs a 0 to›divide into, the is very bad since›a division by 0 doesn't exist.››Look at program APROG.402 for this›program. You will notice that the›divison is not what you would expect.›That is because Action! only has whole›numbers.››In Action! if you:›› PrintBE( 1 / 3)››That is take 1 divided by 3, you will›get 0, NOT .33333›Action! has no decimal notation.››I am getting of the subject but I›feel that since it is used in the ›program it is a good idea to explain›it.››Anyway, the EXIT command is good when›you use it in emergency situations,›when you have to get out of a loop›in a hurry.››A EXIT is also useful when you have›alot of conditions on when to end›a loop.››Like: UNTIL (the user answers yes AND›the record number =0 AND you haven't›reached the end of the file AND you›aren't running out of memory space)››I haven't gone into the actual Action!›statements of those situation yet so›I put them in words. But you get›the picture, there are 4 conditions›to end this loop.››The better thing to do is just have 1›or 2 conditions in the UNTIL statement›and put the others in IF FI with›can EXIT.››MOST other times, if you must have›an EXIT in your loop to make it work›right, you have chosen the wrong›type of loop.››APROG.403 compares doing the same›loop with the 3 looping statements.›Remember, each time a program must›do a loop, it is up to you, the›programmer, do decide which type of›loop to use. For APROG.403, try›and guess which one is BEST. They›all work, but one is best for what›I am trying to accomplish.››That's it for Action!'s looping ›commands. In the next file, we›won't be going into any new Action!›commands. It will cover some›editor and monitor commands that will›make your writing and debugging of›Action! programs faster and easier.››