# Writing pseudocode to be language independent

There exist 5 rules for any pseudocode , one of these rules is : "Keep statements language independent" I don't understand what is this rule is saying. So can someone explain it and then give an example of pseudocode written to be language independent ? Moreover, the source for this rule is "Invitation to Computer Science, 8th Edition by Schneider/Gersting". Thanks in advance

• Welcome to Computer Science! We discourage posts that simply state a problem out of context, and expect the community to solve it. Assuming you tried to solve it yourself and got stuck, it may be helpful if you wrote your thoughts and what you could not figure out. It will definitely draw more answers to your post. Until then, the question will be voted to be closed / downvoted. You may also want to check out these hints, or use the search engine of this site to find similar questions that were already answered. – Raphael Sep 27 '18 at 23:31
• Also, it's not clear who "we" is, and I don't think there are objective answers to this. – Raphael Sep 27 '18 at 23:32
• Is your "5 rules for any pseudocode" coming from this blog on pseudocode? Yes or not, please add a reference to the source in your question. – John L. Sep 27 '18 at 23:42
• Please add the reference to your question instead of in the comment. It is not expected of people to read comments. Also, the title should better be "writing pseudocode to be language independent", which is short enough while giving enough accurate information for search engine to index and for people to read at a glance. If you are indeed very focused, a title such as "explain writing language-independent pseudocode with an example" might be even better. – John L. Sep 27 '18 at 23:56
• What specifically do you want explained? Do you understand what that rule is saying? Do you want to understand the reason for it? Please share your thoughts. This might help us provide you with better answers. – D.W. Sep 28 '18 at 4:19

what is meant by independent is that Pseudocode is a description of a computer programming algorithm that uses structural conventions of a programming language, and is intended to be read by humans and not by machines. Pseudocodes usually do not use elements of sufficient detail that are not necessary for the needs of human understanding of an algorithm, such as variable declarations and codes. so that pseudocode is not tied to any programming language and pseudocode can be implemented in any language, whether it's C ++, Java, Python, or the latest programming language.

example

Start
Enter a, b
c = a + b
Print "c"
Finished


here is the same example, enter the values ​​a and b so as to produce a value of c (sum of a + b)

You can use this pseudocode as a basis for making the addition program from different programming languages.

Java

// File name: Sum.java
// Description: The program displays the sum of 2 numbers

// use the Scanner class
import java.util.Scanner;

{
// the main method before executing the java application
public static void main (String args [])
{
// for the Scanner to get input from the form
Scanner input = new Scanner (System.in);

int number1; // first number
int number2; // second number
int sum; // number of numbers 1 and 2

// cursor 1
System.out.print ("Enter the First Number:");
// reads input number 1 from the user
number1 = input.nextInt ();

// cursor 2
System.out.print ("Entering the Second Number:");
// read input number 2 from the user
number2 = input.nextInt ();

// sum of numbers
sum = number1 + number2;

System.out.printf ("Sum is% d \ n", sum);
} // end method

{

return(a + b);

}


c++

#include <iostream.h>
void main ()
{
int a, b;
float c;

cout << "Enter a:";
cin >> a;
cout << endl;
cout << "Enter the value b:";
cin >> b;
cout << endl;
c = a + b
cout << "The result is =";
cout << c;
}


that's the 2 code example programming language that uses the same pseudocode. hopefully can help you. :)

The rule means roughly that the statements and constructs should be clear and not be directly expressed in any actual programming language. For example, imagine we want to present a silly toy example for an algorithm that determines if the value 5 is present in an array. Perhaps you have never seen C++, but I still give you the following description:

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
std::vector<int> v = { 1, 3, 5, 7 };
auto iter = std::find(v.begin(), v.end(), 5);
if(iter != v.end())
std::cout << "found 5\n";
}


You might be confused and say "what include?", "what std::?", "what vector, find, auto, cout, <<, what is all this garbage?". And you would be absolutely right. My use of a concrete programming language is cluttering the presentation and obscuring what I really want to get across. So here's one possible pseudocode implementation of the above, in the spirit of the rule you mention:

A[1..4] = [1,3,5,7]
for i = 1 to 4:
if A[i] == 5:
print "found 5"


The logic behind the algorithm should be much clearer from this description to someone who has never seen C++ or some specific programming language I might have used.

• "not be directly expressed in any actual programming language" That's overstating it. There's no reason at all that I can't write "if (A[i] == 5)" and call it pseudocode, even though C and Java both use that syntax. And your "if A[i] == 5:" doesn't somehow become invalid if somebody writes a compiler for a language with that syntax. – David Richerby Oct 9 '18 at 23:07
• @DavidRicherby I don't disagree, but I couldn't think of a better way of expressing it. I think what you mention is right but a side issue, and the example makes my answer clear. – Juho Oct 10 '18 at 6:32