伪代码:明确的定义? [英] Pseudocode: a clear definition?

查看:122
本文介绍了伪代码:明确的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码是我认为可以用作伪代码的示例,因为它不以任何语言执行,但逻辑是正确的.

The following code is an example of what I think would qualify as pseudocode, since it does not execute in any language but the logic is correct.

string checkRubric(gpa, major)
    bool brake = false
    num lastRange
    num rangeCounter
    string assignment = "unassigned"
    array bus['business']= array('person a'=>array(0, 2.9), 'person b'=>array(3, 4))
    array cis['computer science']= array('person c'=>array(0, 2.9), 'person d'=>array(3, 4))
    array lib['english']= array('person e'=>array(0, 4))
    array rubric = array(bus, cis, lib)

foreach (rubric as fieldAr)
    foreach (fieldAr as field => advisorAr)
        if (major == field)
            foreach (advisorAr as advisor => gpaRangeAr)
                    rangeCounter = 0
                foreach (gpaRangeAr as gpaValue)
                    if (rangeCounter < 1)
                        lastRange = gpaValue
                    else if (gpa >= lastRange && gpa <= gpaValue)
                        assignment = advisor
                        brake = true
                        break
                    endif
                    rangeCounter++
                endforeach
                if (brake == true)
                    break
                endif
            endforeach
            if (brake == true)
                break
            endif
        endif
    endforeach
    if (brake == true)
        break
    endif
endforeach
return assignment

在过去的几周中,我一直在尝试为实际上是什么伪代码创建一个清晰的定义.是相对于程序员还是实际的明确语法?我说伪代码是任何不执行的代码,你呢?谢谢(欢迎访问此主题的链接)

For the past couple of weeks I've been trying to create a clear definition of what pseudocode actually is. Is it relative to the programmer or is there an actual clearcut syntax? I say pseudocode is any code that does not execute, how about you? Thanks (links to this subject welcome)

推荐答案

没有固定的伪代码定义.您希望您的听众能够理解并传达您的观点的任何表示法.重要的思想是它是供人类阅读而不是计算机阅读的,因此它不必很精确.您可以包括对您的展览很重要的细节,而忽略不重要的细节.

There is no fixed definition of pseudocode. It's any notation that you expect your audience to understand to get your point across. The important idea is that it is intended for humans to read, not computers, so it doesn't have to be precise. You can include the details that are important to your exposition, and omit the ones that are not.

这篇关于伪代码:明确的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆