Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Part_2_Statements_And_Cases
- /*Its time to do dwell more into boolean statements and essentially the fundamental logic behind PCs'
- A statement is a boolean expression. E.g. true is a statement. We can also calculate statments:
- 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)
- Since 2 is never equals to 3, then the boolean evaluation of the statement is always false => (2 == 3) == false
- 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.
- */
- 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");
- Console.WriteLine("there is also less than or equal comperator and its written as <= . The reverse is written as >=. ");
- 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");
- 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.");
- 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 ");
- Console.WriteLine(" smt like if the player coordinates are outside of the game world \n");
- Console.WriteLine("Statments can however be combined. With either OR statments or AND statments.");
- Console.WriteLine("E.g. if we define winter as it has_to_be_cold AND Dec/Jan/ or Feb. ");
- Console.WriteLine("That means winter == true if its jan feb or dec and its cold outside");
- Console.WriteLine("But it also means that if its -40 degrees celsius in mars then its not winter");
- Console.WriteLine("Aka the AND statment is only true if and ONLY if BOTH statments are. ");
- Console.WriteLine("Its written as (statement1 && statement2)"); // OBS: you can combind several ANDs or ORs (aka just not limited to two)
- Console.WriteLine("The OR statment is a bit tricker tho as its not the same as a or in real life");
- Console.WriteLine("If you ask someone to buy apples or pears if there are any at the local supermarket");
- Console.WriteLine("They usually mean to bring only home one. But in boolean logic it would be ok to bring bring home both");
- 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");
- Console.WriteLine("july and -20 degrees. Ofc it would also be winter if it was dec and cold still");
- Console.WriteLine("So Or statments are true if EITHER statment1 OR statment2 OR if statement1 AND statment2 are true.");
- Console.WriteLine("In C# its written as (Statment1 || statement2)"); //You dont need the () always ofc.
- Console.WriteLine("I've touched some on some if statements before but I've tried to exclude them.");
- Console.WriteLine("But you cant do programming without if-statments so here are some examples");
- if(true)
- {
- Console.WriteLine("Now I entered the first case");
- } else
- {
- Console.WriteLine("this wont happen"); // THIS WILL ALWAYS HAPPEN IF ABOVE DONT SUCCEED
- }
- Console.WriteLine("another case");
- if(false)
- {
- Console.WriteLine("this wont happen");
- } else if (true)
- {
- Console.WriteLine("You entered the second case");
- } else if (true)
- {
- Console.WriteLine("You wont enter this case as the one above succeeded");
- }
- Console.WriteLine("Single if cases work too");
- if(false)
- {
- Console.WriteLine("Wont happen either :D");
- }
- //We cant go through if-else cases without doing a switch case thing.
- // This syntax is old and looks kinda stupid but works well if you have larger if questions
- int switchVariable = 0; //TRY
- switch (switchVariable) //This is what the computer analyses before you jump into different cases
- {
- /*
- The syntax for a case is
- case <value> of the SAME TYPE as "switchVariable", be it a string, integer, double or anything
- after the case <value> you end with a colon == :
- <here is your code>
- after you've done your code you break the code with codeword break + ;
- aka "break;"
- */
- case 0:
- //will happen if the number is 0
- break;
- case 1:
- //will happen if the number is one
- break;
- case 2:
- case 3:
- //Will happen if the number above is 2 or 3
- //this means that there can be several cases that lead to the same peice of code.
- break;
- default:
- //This will happen if switch is none of the above. The default case is not always needed
- break;
- }
- //NOW YOU CAN GET THIS JOKE: https://iwsmt-content-ok2nbdvvyp8jbrhdp.stackpathdns.com/7212012232151iwsmt.jpeg
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement