lang_ref_programflow.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type"
  4. content="text/html; charset=iso-8859-1">
  5. <title>Language Reference - Program Flow</title>
  6. <link rel="stylesheet" href="lang_ref.css" type="text/css">
  7. </head>
  8. <body><br>
  9. &nbsp;<span class="Command">&nbsp;Program Flow&nbsp;</span>
  10. <blockquote>
  11. <p>The following constructs are available for controlling program flow. </p>
  12. <p class="header">If ... Then </p>
  13. <blockquote> <i>If {expression} Then {statements1} Else {statements2} </i></blockquote>
  14. </blockquote>
  15. <p>
  16. <blockquote>
  17. <p>Evaluates the 'If' expression and, if true, executes the 'Then' statements.
  18. If false, the 'Else' statement are executed, the 'Else' part is optional -
  19. statements are executed until the end of the line.</p>
  20. <blockquote>
  21. <p><i>If {expression1}<br>
  22. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements1} <br>
  23. Else If {expression2}<br>
  24. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements2} <br>
  25. Else If {expression3}<br>
  26. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements3}<br>
  27. Else <br>
  28. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements4} <br>
  29. EndIf </i></p>
  30. </blockquote>
  31. <p> This form of the If statement allows for more than one line of statements.
  32. The 'Else If' and 'Else' parts are optional. The 'Else' part is executed only
  33. if none of the 'If' or 'Else If' expressions were true. </p>
  34. <p class="header">While ... Wend</p>
  35. </blockquote>
  36. <p>
  37. <p align="left">
  38. <blockquote>
  39. <blockquote>
  40. <p> <i>While {expression} <br>
  41. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements} <br>
  42. Wend </i></p>
  43. </blockquote>
  44. <p> A While loop continues executing until {expression} evaluates to false.
  45. {expression} is evaluated at the start of each loop. </p>
  46. <p class="header">For ... Next</p>
  47. <blockquote>
  48. <p> <i>For {variable}={initalvalue} To {finalvalue} Step {step} <br>
  49. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements} <br>
  50. Next </i></p>
  51. </blockquote>
  52. <p> A For/Next loop first assigns {initialvalue} to {variable} and then starts
  53. looping. The loop continues until {variable} reaches {finalvalue} and then
  54. terminates. Each loop, the value {step} is added to {variable}. If a step
  55. value is omitted, a default value of 1 is used. </p>
  56. <blockquote>
  57. <p><i> For {variable}=Each {typename} <br>
  58. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements} <br>
  59. Next </i></p>
  60. </blockquote>
  61. <p>This form of the For/Next loop allows you to iterate over all objects of
  62. a custom type. </p>
  63. <p class="header">Repeat ... Until/Forever</p>
  64. </blockquote>
  65. <p align="left">
  66. <blockquote>
  67. <blockquote>
  68. <p><i> Repeat <br>
  69. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements} <br>
  70. Until {expression} </i></p>
  71. </blockquote>
  72. <p> A Repeat loop continues executing until {expression} evaluates to true.
  73. {expression} is evaluated at the end of each loop. </p>
  74. <blockquote>
  75. <p><i>Repeat <br>
  76. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements} <br>
  77. Forever</i> </p>
  78. </blockquote>
  79. <p>A Repeat/Forever loop simply executes {statements} until the program ends,
  80. or an 'Exit' command is executed. </p>
  81. <p class="header">Select ... Case</p>
  82. </blockquote>
  83. <p>
  84. <p align="left">
  85. <blockquote>
  86. <blockquote>
  87. <p> <i>Select {expression} <br>
  88. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case {expressions1}<br>
  89. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements1} <br>
  90. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Case {expressions2} <br>
  91. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements2}<br>
  92. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default <br>
  93. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{statements3} <br>
  94. End Select </i></p>
  95. </blockquote>
  96. <p> First the 'Select' expression is evaluated. It is then compared with each
  97. of the 'Case' expression lists. If it matches a 'Case', then the statements
  98. in the 'Case' are executed. </p>
  99. <p> If the 'Select' expression matches none of the 'Case' expressions, the statements
  100. in the optional 'Default' section are executed. </p>
  101. <p class="header">Breaking Out Of A Loop</p>
  102. <p> The 'Exit' command may be used to break out of any <b>For...Next</b>, <b>While...Wend</b>,
  103. <b>Repeat...Until</b> or <b>Repeat...Forever</b> loop. </p>
  104. <p class="header">Using Includes</p>
  105. <p>Blitz also supports the 'Include' command. Include allows source code from
  106. an external file to be compiled as if it were part of the main program. Include
  107. must be followed by a quote enclosed filename. For example... </p>
  108. </blockquote>
  109. <p>
  110. <p align="left">
  111. <blockquote> Include "anotherfile.bb"
  112. <p> Include allows you to break your program up into smaller, more manageable
  113. chunks. </p>
  114. </blockquote>
  115. </body>
  116. </html>