Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pseudocode
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Syntax== Pseudocode generally does not actually obey the [[syntax]] rules of any particular language; there is no systematic standard form. Some writers borrow style and syntax from control structures from some conventional programming language, although this is discouraged.<ref>{{cite book|title=Code Complete|title-link=Code Complete|page=54 |quote=Avoid syntactic elements from the target programming language|first1=Steve|last1=McConnell|authorlink=Steve McConnell|isbn=978-0-7356-1967-8 |date=2004|publisher=Pearson Education }}</ref><ref>Invitation to Computer Science, 8th Edition by Schneider/[[Judith Gersting|Gersting]], "Keep statements language independent" as quoted [https://cs.stackexchange.com/questions/97851/writing-pseudocode-to-be-language-independent in this stackexchange question]</ref> Some syntax sources include [[Fortran]], [[Pascal (programming language)|Pascal]], [[BASIC]], [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]], [[Lisp (programming language)|Lisp]], and [[ALGOL]]. Variable declarations are typically omitted. Function calls and blocks of code, such as code contained within a loop, are often replaced by a one-line natural language sentence. Depending on the writer, pseudocode may therefore vary widely in style, from a near-exact imitation of a real programming language at one extreme, to a description approaching formatted prose at the other. This flexibility brings both major advantages and drawbacks: on the positive side, no executable programming language "can beat the convenience of inventing new constructs as needed and letting the reader try to deduce their meaning from informal explanations", on the negative, "untested code is usually incorrect".<ref>{{cite web |last1=Lamport |first1=Leslie |url=https://www.microsoft.com/en-us/research/uploads/prod/2016/12/The-PlusCal-Algorithm-Language.pdf |publisher=Microsoft Research |access-date=28 May 2024 | title = The PlusCal Algorithm Language |date=2 January 2009}}</ref> {| class="wikitable" |+ An example of pseudocode (for the [[mathematical game]] [[fizz buzz]]) |-valign="top" || Pascal style: <syntaxhighlight lang="Pascal" style="font-size:85%"> procedure fizzbuzz; for i := 1 to 100 do print_number := true; if i is divisible by 3 then begin print "Fizz"; print_number := false; end; if i is divisible by 5 then begin print "Buzz"; print_number := false; end; if print_number, print i; print a newline; end </syntaxhighlight> || C style: <syntaxhighlight lang="C" style="font-size:85%"> fizzbuzz() { for (i = 1; i <= 100; i++) { print_number = true; if (i is divisible by 3) { print "Fizz"; print_number = false; } if (i is divisible by 5) { print "Buzz"; print_number = false; } if (print_number) print i; print a newline; } } </syntaxhighlight> || Python style: <syntaxhighlight lang="Python" style="font-size:85%"> def fizzbuzz(): for i in range(1,101): print_number = true if i is divisible by 3: print "Fizz" print_number = false if i is divisible by 5: print "Buzz" print_number = false if print_number: print i print a newline </syntaxhighlight> |} {{Category see also|Articles with example pseudocode}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)