Difference between revisions of "Pseudocode"

From Conservapedia
Jump to navigation Jump to search
(added example)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
−
'''Pseudocode''' is a form of "mock" [[computer code]] to help build [[algorithm]]s in an actual computer programming language.  The code is written to show logical flow and design for the program and should be in a form that non-[[computing]] professionals can understand.
+
'''Pseudocode''' is a form of "mock" [[computer code]].  Unlike most computer code, it's intended to be understood only by humans, and usually can't be parsed by a [[compiler]] or [[interpreter (programming)|interpreter]].  Pseudocode is often shorter than the equivalent source code, because it seeks to be more understandable by glossing over less important details. Pseudocode is used for instructional purposes (particularly in introductory courses), for discussing an algorithm in a somewhat language-neutral way, or for building an initial skeleton in a low-level design document.
  
−
[[category:Computer Science]]
+
==Example==
 +
In [[C++|C++ code]], an "if/else" statement is as follows:<br />
 +
<code><nowiki>
 +
if ( pi < 4 ) {</nowiki><br /><nowiki>
 +
&nbsp;cout << "pi is approximately correct";</nowiki><br /><nowiki>
 +
}</nowiki><br /><nowiki>
 +
else if ( pi >= 4 ) {</nowiki><br /><nowiki>
 +
&nbsp;cout << "pi is not set correctly";</nowiki><br /><nowiki>
 +
}</nowiki><br /><nowiki>
 +
else {</nowiki><br /><nowiki>
 +
&nbsp;cout << "an error has occurred";</nowiki><br /><nowiki>
 +
}</nowiki></code>
 +
 
 +
The pseudocode may look something like this:<br />
 +
<code><nowiki>
 +
if pi is < 4</nowiki><br /><nowiki>
 +
&nbsp;say "pi is approximately correct"</nowiki><br /><nowiki>
 +
if pi is >= 4 </nowiki><br /><nowiki>
 +
&nbsp;say "pi is not set correctly"</nowiki><br /><nowiki>
 +
otherwise say "an error has occurred"</nowiki></code>
 +
== References ==
 +
* [http://www.cs.cornell.edu/Courses/cs482/2003su/handouts/pseudocode.pdf Pseudocode guidelines, CS 341, Cornell]
 +
 
 +
[[Category:Computer Science]]

Latest revision as of 04:23, September 28, 2016

Pseudocode is a form of "mock" computer code. Unlike most computer code, it's intended to be understood only by humans, and usually can't be parsed by a compiler or interpreter. Pseudocode is often shorter than the equivalent source code, because it seeks to be more understandable by glossing over less important details. Pseudocode is used for instructional purposes (particularly in introductory courses), for discussing an algorithm in a somewhat language-neutral way, or for building an initial skeleton in a low-level design document.

Example

In C++ code, an "if/else" statement is as follows:
if ( pi < 4 ) {
 cout << "pi is approximately correct";
}
else if ( pi >= 4 ) {
 cout << "pi is not set correctly";
}
else {
 cout << "an error has occurred";
}

The pseudocode may look something like this:
if pi is < 4
 say "pi is approximately correct"
if pi is >= 4
 say "pi is not set correctly"
otherwise say "an error has occurred"

References