It should be noted that that value of changes 5 x in sequence, line by line as it is interpreted, at the start of line 3 (x=x+y) still has a value of x 3 but once that line is run it then changes to be or 5. x+y C# int x, y; x = 3; y = 2; x = x + y; Console.WriteLine(x); Selection Pseudocode Selection will be carried out with if/else and if entry==“a” then switch/case. In this example, the print(“You selected A”) pseudocode is checking the input and elseif entry==“b” then returning a message based upon the specific print(“You selected B”) input given, the else block is used as a catch for any unexpected input which allows the else code to degrade gracefully. print(“Unrecognised selection”) endif The switch/case method works in the same way. The CASE SELECT is slightly switch entry: different in that you always have to case “A”: have the print(“You selected A”) ‘default’ case. case “B”: This effectively creates a for print(“You selected B”) ‘Catch’ when invalid entry is recognized. In default: print(“Unrecognised selection”) an IF statement you would have to specifically create an ELSE construct endswitch to cope for this. IF or CASE Select? IF statements use relational operators to make decisions. Is a variable equal to that variable, is it greater than etc. Case Selects only look for exact matches, via the Therefore you have to make a ‘case’ line. decision as to what choice you are making, as to which may be most appropriate. C#
5 It should be noted that that value of x changes in sequence, line by line as it is interpreted, at the start of line 3 (x=x+y) x still has a value of 3 but once that line is run it then changes to be x+y or 5. C# int x, y; x = 3; y = 2; x = x + y; Console.WriteLine(x); Selection Pseudocode if entry==“a” then print(“You selected A”) elseif entry==“b” then print(“You selected B”) else print(“Unrecognised selection”) endif Selection will be carried out with if/else and switch/case. In this example, the pseudocode is checking the input and returning a message based upon the specific input given, the else block is used as a catch for any unexpected input which allows the code to degrade gracefully. The switch/case method works in the same way. switch entry: case “A”: print(“You selected A”) case “B”: print(“You selected B”) default: print(“Unrecognised selection”) endswitch The CASE SELECT is slightly different in that you always have to have the ‘default’ case. This effectively creates a ‘Catch’ for when invalid entry is recognized. In an IF statement you would have to specifically create an ELSE construct to cope for this. IF or CASE Select? IF statements use relational operators to make decisions. Is a variable equal to that variable, is it greater than etc. Case Selects only look for exact matches, via the ‘case’ line. Therefore you have to make a decision as to what choice you are making, as to which may be most appropriate. C#
398694-programming-techniques-c-teacher-guide.docx