Pseudo code example

3.3k views Asked by At

I am new to programming in general and I am trying to learn the basics of it. Could someone explain me the concept of Pseudo code. I have already done some research but an additional help would be great. As an example, what would pseudo code for making a peanut butter and jelly sandwich would look like?

-Thank you.

1

There are 1 answers

0
Ludricio On BEST ANSWER

Pseudo code is a simplified language designed to express ideas in programming without using the syntax of a specific programming language. It is a way to express algorithms in a compact and understandable form, making it easier to discuss and understand the code without actually writing it.

Pseudo code can either consist of real code-like examples, or just pure text.

An example of a pseudo code for making a PBJ could look something like this:

MakePBJRoutine(input: peanut butter, jelly, bottom bread, top bread) 
Begin routine:
        Take bottom bread. 
        Spread peanut butter on bottom bread. 
        Spread jelly on bottom bread. 
        If want more jelly:
              Spread jelly on bottom bread. 
        Place top bread slice on bottom bread
        Return finished sandwich
End routine 
    

Meanwhile, it could also look like this.

makePBJroutine(input: P, J, TB, BB; Out: PBJ) {
     BB <- P;
     BB <- J;
     If(BB.J < PreferredJellyAmountConstant){
         BB <- J;
     } 
    PBJ <- (BB <- TB);
    Return PBJ;
}