code_junkie

What to put in the IF block and what to put in the ELSE block?

Nov 11th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. if (condition) then
  2. {
  3. // do stuff
  4. }
  5. else
  6. {
  7. // do other stuff
  8. }
  9.  
  10. if (!condition) then
  11. {
  12. // do other stuff
  13. {
  14. else
  15. {
  16. // do stuff
  17. }
  18.  
  19. if (condition)
  20. return;
  21.  
  22. DoSomething();
  23.  
  24. bool MyFunc(variable) {
  25. if (variable != something_i_want)
  26. return false;
  27.  
  28. // a large block of code
  29. // ...
  30. return true;
  31. }
  32.  
  33. if (!some_function_that_could_fail())
  34. {
  35. // Error handling code
  36. }
  37. else
  38. {
  39. // Success code
  40. }
  41.  
  42. if (somePositiveCondition)
  43. else {
  44. //stuff
  45. }
  46.  
  47. if DataIsGood() then
  48. DoMyNormalStuff
  49. else
  50. TakeEvasiveAction
  51.  
  52. if SomeErrorTest then
  53. TakeSomeEvasiveAction
  54. else if SomeOtherErrorCondition then
  55. CorrectMoreStupidUserProblems
  56. else if YetAnotherErrorThatNoOneThoughtOf then
  57. DoMoreErrorHandling
  58. else
  59. DoMyNormalStuff
  60.  
  61. if (blah == false)
  62. {
  63. return; // perhaps with a message
  64. }
  65.  
  66. // do rest of code here...
  67.  
  68. if (not_dead) {
  69. } else {
  70. }
  71.  
  72. if (alive) {
  73. } else {
  74. }
  75.  
  76. if (!alive) {
  77. } else {
  78. }
  79.  
  80. if (dead || (!dead && sleeping)) {
  81. } else {
  82. }
  83.  
  84. if (dead || sleeping) {
  85. } else {
  86. }
  87.  
  88. if( common ) {
  89. // pass
  90. }
  91. else {
  92. // great big block of exception-handling folderol
  93. }
  94.  
  95. if( ! common ) {
  96. // great big block of except-handling folderol
  97. }
  98.  
  99. if (!PreserveData.Checked)
  100. { resetfields();}
  101.  
  102. if (!widget.enabled()) {
  103. // more common
  104. } else {
  105. // less common
  106. }
  107.  
  108. if (widget.disabled()) {
  109. // more common
  110. } else {
  111. // less common
  112. }
  113.  
  114. if (expected)
  115. {
  116. //expected path
  117. }
  118. else
  119. {
  120. //fallback other odd case
  121. }
  122.  
  123. unless ($foo) {
  124. $bar;
  125. }
  126.  
  127. //if you must have multiple exit points, put them first and make them clear
  128. if TerminatingCondition1 then
  129. Exit
  130. if TerminatingCondition2 then
  131. Exit
  132.  
  133. //now we can progress with the usual stuff
  134. if NormalThing then
  135. DoNormalThing
  136. else
  137. DoAbnormalThing
  138.  
  139. unless (alive) {
  140. go_to_heaven;
  141. } else {
  142. say "MEDIC";
  143. }
Add Comment
Please, Sign In to add comment