|
Introduction to Condition StatementsIF .. THEN .. ELSE There are 2 ways to use IF .. THEN .. ELSE. You can place your statement on one single line like so: IF I > 100 THEN PRINT "I is greater than 100"Or split it up like so: IF I > 100 THEN PRINT "I is greater than 100" END IFAs you can see, I > 100 is a condition, as long as this is satisfied, the code gets executed, if not then that piece of code is skipped. A condition is satisfied whenever the expression evaluates to any non-zero number. Which also means that this is valid: I = 100 IF I THEN PRINT "Condition satisfied" ELSE PRINT "Condition is not satisfied" END IFUse ELSEIF whenever you have multiple conditions that you want satisfied: IF I > 10 AND I <20 THEN '' do stuff ELSEIF I > 55 THEN '' do stuff ELSE '' do stuff END IFSometimes it helps to use SELECT CASE instead of all these ELSEIFs, which we'll cover next. SELECT CASE .. END SELECT Select cases are usually implemented when you have a lot of conditions that you want to test for. It's really not useful if you only have 2 or 3 conditions, but no one's stopping you from using it. There are no special cases in using SELECT CASEs in Rapid-Q, so everything you learned in QBasic, can be implemented here as well. SELECT CASE Expression CASE 1 '' Do stuff CASE 5 '' Do stuff CASE ELSE '' No conditions satisfied, do stuff END SELECTIt probably involves less typing, but there are many other useful purposes, for example, range testing becomes so much easier: SELECT CASE Expression CASE 1 TO 4, 10 TO 20 '' Do stuff CASE 100 TO 150 '' Do stuff CASE IS > 200 '' Do stuff END SELECTAs you can see, you can have multiple test conditions by separating each with a comma. I think you can figure out how the IS keyword is used.
|
Questions? Comments? E-Mail the Webmaster: webmaster@RapidQers.freeservers.com |