Case.htm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>Case value [,value [,value ... ] ]</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. value = any valid value of the SELECT variable
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. When using a SELECT structure, the CASE command defines the starting point of command execution if the SELECT value matches the CASE value. If the SELECT value doesn't match the CASE value, the commands following it are ignored until the next CASE, DEFAULT, or END SELECT command is encountered. See SELECT and the example for a better understanding. <br />
  21. <br />
  22. If multiple values should result in the same outcome, a single CASE statement can be used with each value separated by commas. <br />
  23. <br />
  24. If you wish to use ranges for a case statement, or if you wish to test more than one variable, you will need to use a programming trick illustrated in the example below. This involves using SELECT TRUE initially, and then in each Case statement specify a logical expression such as A > 1 AND A < 4.
  25. <br>
  26. <br>
  27. See also: <a class=small href=Select.htm>Select</a>, <a class=small href=Default.htm>Default</a>, <a class=small href=End Select.htm>End Select</a>.
  28. </td>
  29. </tr>
  30. </table>
  31. <h1><a href=../2d_examples/Case.bb>Example</a></h1>
  32. <table>
  33. <tr>
  34. <td>
  35. ; Advanced SELECT/CASE/DEFAULT/END SELECT Example <br />
  36. ; Assign a random number 1-10 <br />
  37. mission=Rnd(1,10) <br />
  38. <br />
  39. ; Start the selection process based on the value of 'mission' variable <br />
  40. Select True <br />
  41. <br />
  42. ; Is mission = 1? <br />
  43. Case mission=1 <br />
  44. Print "Your mission is to get the plutonium and get out alive!" <br />
  45. <br />
  46. ; Is mission = 2? <br />
  47. Case mission=2 <br />
  48. Print "Your mission is to destroy all enemies!" <br />
  49. <br />
  50. ; Is mission = 3 to 5 <br />
  51. Case mission>=3 And mission<=5 <br />
  52. Print "Your mission is to steal the enemy building plans!" <br />
  53. <br />
  54. ; What do do if none of the cases match the value of mission <br />
  55. Default <br />
  56. Print "Missions 6-10 are not available yet!" <br />
  57. <br />
  58. ; End the selection process <br />
  59. End Select
  60. </td>
  61. </tr>
  62. </table>
  63. <br>
  64. <a target=_top href=../index.htm>Index</a><br>
  65. <br>
  66. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Case&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  67. </html>