Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. #region Part_2_Statements_And_Cases
  2.  
  3. /*Its time to do dwell more into boolean statements and essentially the fundamental logic behind PCs'
  4. A statement is a boolean expression. E.g. true is a statement. We can also calculate statments:
  5. an example shown before is if e.g. 2 == 3 (notice the double equals signs. If its a single '=' then its a decleration whilst a double == is evaluated into a boolean)
  6. Since 2 is never equals to 3, then the boolean evaluation of the statement is always false => (2 == 3) == false
  7. Fun fact; the previous statement is true, as (2 == 3) == false is a true statment. as 2==3 is false and false == false, then thats true.
  8. */
  9.  
  10.  
  11. Console.WriteLine("There are other ways to make statements, there is for example the <, aka the less than comperator. 2 < 3 is e.g. true. Whilst 2 > 3 is false");
  12. Console.WriteLine("there is also less than or equal comperator and its written as <= . The reverse is written as >=. ");
  13. Console.WriteLine("An example of the latter is 2 is less than or equal to 3, aka 2 <= 3 == true. 3 <= 3 is also true");
  14. Console.WriteLine("Another comperator is not equal to. Its written as != and an example of this is 2 != 3 == true. 2 != 3 is however false.");
  15. Console.WriteLine("Now comparing static numbers is probably boring. But this is useful af with variables. E.g. a common statement that might be calculated is ");
  16. Console.WriteLine(" smt like if the player coordinates are outside of the game world \n");
  17.  
  18. Console.WriteLine("Statments can however be combined. With either OR statments or AND statments.");
  19. Console.WriteLine("E.g. if we define winter as it has_to_be_cold AND Dec/Jan/ or Feb. ");
  20. Console.WriteLine("That means winter == true if its jan feb or dec and its cold outside");
  21. Console.WriteLine("But it also means that if its -40 degrees celsius in mars then its not winter");
  22. Console.WriteLine("Aka the AND statment is only true if and ONLY if BOTH statments are. ");
  23. Console.WriteLine("Its written as (statement1 && statement2)"); // OBS: you can combind several ANDs or ORs (aka just not limited to two)
  24.  
  25.  
  26. Console.WriteLine("The OR statment is a bit tricker tho as its not the same as a or in real life");
  27. Console.WriteLine("If you ask someone to buy apples or pears if there are any at the local supermarket");
  28. Console.WriteLine("They usually mean to bring only home one. But in boolean logic it would be ok to bring bring home both");
  29. Console.WriteLine("If we go back to the prev example with winter. In OR-statments it would be winter if it was january and 35*C or");
  30. Console.WriteLine("july and -20 degrees. Ofc it would also be winter if it was dec and cold still");
  31. Console.WriteLine("So Or statments are true if EITHER statment1 OR statment2 OR if statement1 AND statment2 are true.");
  32. Console.WriteLine("In C# its written as (Statment1 || statement2)"); //You dont need the () always ofc.
  33.  
  34. Console.WriteLine("I've touched some on some if statements before but I've tried to exclude them.");
  35. Console.WriteLine("But you cant do programming without if-statments so here are some examples");
  36.  
  37. if(true)
  38. {
  39. Console.WriteLine("Now I entered the first case");
  40. } else
  41. {
  42. Console.WriteLine("this wont happen"); // THIS WILL ALWAYS HAPPEN IF ABOVE DONT SUCCEED
  43. }
  44.  
  45. Console.WriteLine("another case");
  46.  
  47. if(false)
  48. {
  49. Console.WriteLine("this wont happen");
  50. } else if (true)
  51. {
  52. Console.WriteLine("You entered the second case");
  53. } else if (true)
  54. {
  55. Console.WriteLine("You wont enter this case as the one above succeeded");
  56. }
  57.  
  58. Console.WriteLine("Single if cases work too");
  59.  
  60. if(false)
  61. {
  62. Console.WriteLine("Wont happen either :D");
  63. }
  64.  
  65. //We cant go through if-else cases without doing a switch case thing.
  66. // This syntax is old and looks kinda stupid but works well if you have larger if questions
  67.  
  68. int switchVariable = 0; //TRY
  69.  
  70. switch (switchVariable) //This is what the computer analyses before you jump into different cases
  71. {
  72. /*
  73. The syntax for a case is
  74. case <value> of the SAME TYPE as "switchVariable", be it a string, integer, double or anything
  75. after the case <value> you end with a colon == :
  76. <here is your code>
  77. after you've done your code you break the code with codeword break + ;
  78. aka "break;"
  79. */
  80. case 0:
  81. //will happen if the number is 0
  82. break;
  83. case 1:
  84. //will happen if the number is one
  85. break;
  86. case 2:
  87. case 3:
  88. //Will happen if the number above is 2 or 3
  89. //this means that there can be several cases that lead to the same peice of code.
  90. break;
  91. default:
  92. //This will happen if switch is none of the above. The default case is not always needed
  93. break;
  94.  
  95. }
  96.  
  97. //NOW YOU CAN GET THIS JOKE: https://iwsmt-content-ok2nbdvvyp8jbrhdp.stackpathdns.com/7212012232151iwsmt.jpeg
  98.  
  99.  
  100. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement