Pseudo code example [closed]

我与影子孤独终老i 提交于 2019-12-13 11:29:47

问题


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:


Pseudo code is meant to describe and describe the flow, structure and logical statements of a program or and algorithm (in most cases only parts of it) in a way that is easy to understand without needing to analyze actual code, and can also be understood by those without any programming knowledge.

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;
}


来源:https://stackoverflow.com/questions/41516963/pseudo-code-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!