Pseudocode

**__Pseudocode __**
====Pseudocode is the level in-between structured English and programming language. It describes the entire logic of the algorithm ==== ==== so that implementation becomes a rote mechanical task of translating line by line into source code. ====

====For looping and selection, The keywords that are to be used include Do While...EndDo; Do Until...Enddo; Case...EndCase; ==== ====If...Endif; Call ... with (parameters); Call; Return ....; Return; When; Always use scope terminators for loops and iteration. ====

====As verbs, use the words Generate, Compute, Process, etc. Words such as set, reset, increment, compute, calculate, add, ==== ====sum, multiply, ... print, display, input, output, edit, test, etc. with careful indentation tend to foster desirable pseudocode. ====

 Pseudocode is so named to reflect the fact that although it is like code, it is not actual programming code. Pseudo means false. The syntax of pseudocode is less strict than the syntax of a programming language - there is no compiler or debugger telling you that you have not placed a semi-colon at the end of the line.There are lots of versions of pseudocode and no single standard. We tend to write a little more detail in pseudocode than we do in Structured English. It is, perhaps, a little closer to the code we may write in our programming language.

Sequence
As before, statements are written in the order in which they need to be executed. Look carefully at the example to see how input, output and assignment are handled in pseudocode. Input Hours Input Rate Wage ← Hours * Rate Output wage

Selection
If hours > 40 THEN overtime ← hours - 40 pay ← pay + overtime * 3.75 EndIfIf average > 50 THEN Output "Pass" ELSE Output "Fail" EndIfIf x In [0 ... 9, A, B, C, D, E, F] THEN Output "Valid Hex" ELSE Output "Bad Hex" EndIfCase x Of 1: Output "January" 2: Output "February" 3: Output "March" EndCase

<span style="color: #000080; font-size: 16px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding: 0px; text-align: left;">Iteration
<span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">For x ← 1 To 12 Output x EndFor <span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">This executes the statement, // Output x // 12 times. The variable x is called a ** stepper ** variable. Each time the loop executes, the value of x increases by 1. The output from this algorithm would be the numbers 1 to 12. <span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">Repeat x ← x + 1 Until x = 6 <span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">In this example, the statement within the construct will be executed at least once. If the code prior to that shown in the example makes x have a value that cannot reach six by repeatedly adding 1, the loop will continue indefinitely or until an overflow occurs because these is not enough memory to store the value of x. The loop executes at least once. <span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">While x < 6 Do x ← x + 1 EndWhile <span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">In this example, the value of x is examined before executing the statements contained within the loop. The statement will not execute if, at this point in the program, x has a value of 6 or greater. <span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">For Each x In [5, 7, 9] Output x EndFor

<span style="color: #000080; font-size: 16px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 10px; padding: 0px; text-align: left;">From Pseudocode To C#
<span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">The following pseudocode describes an algorithm for adding two numbers together and reporting their sum and average. <span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">Input Number1 Input Number2 Sum ← Number1 + Number2 Average ← Sum / 2 Output Sum, Average <span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">When we write this in C#, we get the following, <span style="background-attachment: initial; background-clip: initial; background-color: #f8f4f1; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border: 1px dashed #d7c3c3; display: block; font: normal normal normal 13px/normal 'Lucida Console','courier new',monospace; margin-bottom: 4px; margin-left: 8px; margin-right: 8px; margin-top: 4px; overflow-x: auto; overflow-y: auto; padding: 8px; text-align: left;">double number1; double number2; double sum; double average; Console.Write("Input Number 1: "); number1 = System.Convert.ToDouble(Console.ReadLine); Console.Write("Input Number 2: "); number2 = System.Convert.ToDouble(Console.ReadLine); sum = number1 + number2; average = sum / 2; Console.WriteLine("Sum: {0}, Average: {1}", sum, average); Console.ReadLine; <span style="color: #000000; font-size: 12px; line-height: 16px; margin-bottom: 8px; margin-left: 0px; margin-right: 0px; margin-top: 6px; padding: 0px; text-align: justify; width: 674px;">There is quite a difference. When we write an algorithm, we are more concerned with whether we are doing the right thing to achieve the result than we are with the exact form of the statements that we need in a programming language. As a result, our actual code is longer and more fussy. Ultimately, it is easier to see if the logic of the algorithm is correct in the shorter, more concise form offered by pseudocode.