Skip to content
2012.12.02 19:52


조회 수 4705 추천 수 0 댓글 0


Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄


Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Pseudocode is a kind of structured english for describing algorithms. It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax.  At the same time, the pseudocode needs to be complete.  It describe the entire logic of the algorithm so that implementation becomes a rote mechanical task of translating line by line into source code.

In general the vocabulary used in the pseudocode should be the vocabulary of the problem domain, not of the implementation domain.  The pseudocode is a narrative for someone who knows the requirements (problem domain) and is trying to learn how the solution is organized.  E.g.,

Extract the next word from the line (good)
set word to get next token (poor)

Append the file extension to the name (good)
name = name + extension (poor)

FOR all the characters in the name (good)
FOR character = first to last (ok)

Note that the logic must be decomposed to the level of a single loop or decision. Thus "Search the list and find the customer with highest balance" is too vague because it takes a loop AND a nested decision to implement it. It's okay to use "Find" or "Lookup" if there's a predefined function for it such as String.indexOf().

Each textbook and each individual designer may have their own personal style of pseudocode. Pseudocode is not a rigorous notation, since it is read by other people, not by the computer. There is no universal "standard" for the industry, but for instructional purposes it is helpful if we all follow a similar style. The format below is recommended for expressing your solutions in our class.

The "structured" part of pseudocode is a notation for representing six specific structured programming constructs: SEQUENCE, WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE. Each of these constructs can be embedded inside any other construct. These constructs represent the logic, or flow of control in an algorithm.

It has been proven that three basic constructs for flow of control are sufficient to implement any "proper" algorithm.

SEQUENCE is a linear progression where one task is performed sequentially after another.
WHILE is a loop (repetition) with a simple conditional test at its beginning.
IF-THEN-ELSE is a decision (selection) in which a choice is made between two alternative courses of action.

Although these constructs are sufficient, it is often useful to include three more constructs:

REPEAT-UNTIL is a loop with a simple conditional test at the bottom.
CASE is a multiway branch (decision) based on the value of an expression. CASE is a generalization of IF-THEN-ELSE.
FOR is a "counting" loop.


Sequential control is indicated by writing one action after another, each action on a line by itself, and all actions aligned with the same indent. The actions are performed in the sequence (top to bottom) that they are written.

Example (non-computer)

Brush teeth
Wash face
Comb hair
Smile in mirror


READ height of rectangle
READ width of rectangle
COMPUTE area as height times width

Common Action Keywords

Several keywords are often used to indicate common input, output, and processing operations.
Initialize: SET, INIT


Binary choice on a given Boolean condition is indicated by the use of four keywords: IF, THEN, ELSE, and ENDIF. The general form is:

IF condition THEN
sequence 1
sequence 2

The ELSE keyword and "sequence 2" are optional. If the condition is true, sequence 1 is performed, otherwise sequence 2 is performed.


IF HoursWorked > NormalMax THEN
Display overtime message
Display regular time message


The WHILE construct is used to specify a loop with a test at the top. The beginning and ending of the loop are indicated by two keywords WHILE and ENDWHILE. The general form is:

WHILE condition

The loop is entered only if the condition is true. The "sequence" is performed for each iteration. At the conclusion of each iteration, the condition is evaluated and the loop continues as long as the condition is true.


WHILE Population < Limit
Compute Population as Population + Births - Deaths


WHILE employee.type NOT EQUAL manager AND personCount < numEmployees
INCREMENT personCount
CALL employeeList.getPerson with personCount RETURNING employee


A CASE construct indicates a multiway branch based on conditions that are mutually exclusive. Four keywords, CASE, OF, OTHERS, and ENDCASE, and conditions are used to indicate the various alternatives. The general form is:

CASE expression OF
condition 1 : sequence 1
condition 2 : sequence 2
condition n : sequence n
default sequence

The OTHERS clause with its default sequence is optional. Conditions are normally numbers or characters

indicating the value of "expression", but they can be English statements or some other notation that specifies the condition under which the given sequence is to be performed. A certain sequence may be associated with more than one condition.


        CASE  Title  OF
                Mr      : Print "Mister"
                Mrs     : Print "Missus"
                Miss    : Print "Miss"
                Ms      : Print "Mizz"
                Dr      : Print "Doctor"


        CASE  grade  OF
                A       : points = 4
                B       : points = 3
                C       : points = 2
                D       : points = 1
                F       : points = 0


This loop is similar to the WHILE loop except that the test is performed at the bottom of the loop instead of at the top. Two keywords, REPEAT and UNTIL are used. The general form is:

UNTIL condition

The "sequence" in this type of loop is always performed at least once, because the test is peformed after the sequence is executed. At the conclusion of each iteration, the condition is evaluated, and the loop repeats if the condition is false. The loop terminates when the condition becomes true.


This loop is a specialized construct for iterating a specific number of times, often called a "counting" loop.  Two keywords, FOR and ENDFOR are used. The general form is:

FOR iteration bounds

In cases where the loop constraints can be obviously inferred it is best to describe the loop using problem domain vocabulary.


FOR each month of the year (good)
FOR month = 1 to 12 (ok)

FOR each employee in the list (good)
FOR empno = 1 to listsize (ok)


The constructs can be embedded within each other, and this is made clear by use of indenting. Nested constructs should be clearly indented from their surrounding constructs.


SET total to zero
READ Temperature
IF Temperature > Freezing THEN
    INCREMENT total
UNTIL Temperature < zero
Print total

In the above example, the IF construct is nested within the REPEAT construct, and therefore is indented.


Use the CALL keyword. For example:

CALL AvgAge with StudentAges
CALL Swap with CurrentItem and TargetItem
CALL Account.debit with CheckAmount
CALL getBalance RETURNING aBalance
CALL SquareRoot with orbitHeight RETURNING nominalOrbit


        WHEN exception type
            statements to handle exception
        WHEN another exception type
            statements to handle exception

Sample Pseudocode


FOR X = 1 to 10

    FOR Y = 1 to 10
        IF gameBoard[X][Y] = 0
            Do nothing
            CALL theCall(X, Y) (recursive method)
            increment counter                 
        END IF


Set moveCount to 1
FOR each row on the board
    FOR each column on the board
        IF gameBoard position (row, column) is occupied THEN
            CALL findAdjacentTiles with row, column
            INCREMENT moveCount
        END IF

(Note: the logic is restructured to omit the "do nothing" clause)

"Not So Good"

FOR all the number at the back of the array
    SET Temp equal the addition of each number
    IF > 9 THEN
        get the remainder of the number divided by 10 to that index
        and carry the "1"
    Decrement one
Do it again for numbers before the decimal

"Good Enough (not perfect)"

SET Carry to 0
FOR each DigitPosition in Number from least significant to most significant

    COMPUTE Total as sum of FirstNum[DigitPosition] and SecondNum[DigitPosition] and Carry  

    IF Total > 10 THEN
        SET Carry to 1
        SUBTRACT 10 from Total
        SET Carry to 0
    END IF

    STORE Total in Result[DigitPosition]


IF Carry = 1 THEN
    RAISE Overflow exception


"Pretty Good"  This example shows how pseudocode is written as comments in the source file. Note that the double slashes are indented.

public boolean moveRobot (Robot aRobot)
    //IF robot has no obstacle in front THEN
        // Call Move robot
        // Add the move command to the command history
        // RETURN true
        // RETURN false without moving the robot
    //END IF

Example Java Implementation

  • source code statements are interleaved with pseudocode.
  • comments that correspond exactly to source code are removed during coding.

public boolean moveRobot (Robot aRobot)
    //IF robot has no obstacle in front THEN
    if (aRobot.isFrontClear())
        // Call Move robot
        // Add the move command to the command history
        return true;
    else // don't move the robot
        return false;
    }//END IF


Document History

Date Author Change
Added Exception Handling and more examples
2/21/03 JD Added "problem domain vocabulary" paragraph.
Modified FOR loop explanation.


출처 : http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html


공부 게시판

공부에 도움되는 글을 올려주세요.

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 [공지] 공부 게시판 입니다. 처누 2003.08.17 828785
1156 논문 Pseudo code 기반의 UML 툴에 대한 아이디어.. JaeSoo 2012.12.02 3623
» 논문 PSEUDOCODE STANDARD JaeSoo 2012.12.02 4705
1154 유닉스/리눅스 Micosoft Windows에서 리눅스를 coLinux!! file JaeSoo 2012.11.29 5049
1153 모바일 안드로이드폰 네이버 캘린더 위젯이 갑자기 안보임 JaeSoo 2012.11.26 6132
1152 육아,교육 2013년 보육료지원 보육정책 자세히 알아보아요!! file JaeSoo 2012.11.23 6820
1151 육아,교육 [2013년 누리과정도입(무상보육지원) 및 양육수당 확대] 내년 만3~4세아 누리과정 도입, 만0~2세아 양육수당 지원확대 file JaeSoo 2012.11.23 4388
1150 경제 대출을 둘러싼 불편한 진실 3부 JaeSoo 2012.11.22 3141
1149 경제 대출을 둘러싼 불편한 진실 2부 JaeSoo 2012.11.22 3033
1148 경제 대출을 둘러싼 불편한 진실 1부 JaeSoo 2012.11.22 3043
1147 경제 성인용품 쇼핑몰 불법인가요? 2 JaeSoo 2012.11.22 4553
1146 기타 성인용품, 해외구매 가능할까? file JaeSoo 2012.11.22 3666
1145 웹 프로그래밍 Xpress engine nginx rewrite 설정, 짧은주소 (xpressengine) file JaeSoo 2012.11.20 19773
1144 웹 프로그래밍 NGINX 소개와 사용 현황 file JaeSoo 2012.11.19 4643
1143 웹 프로그래밍 강력한 웹서버 NGINX JaeSoo 2012.11.19 4975
1142 웹 프로그래밍 Nginx 웹서버 성능분석 file JaeSoo 2012.11.19 4097
1141 경제 SKT 요금약정 할인제도 파헤치기 JaeSoo 2012.11.16 2390
1140 하드웨어 CPU TDP(열 설계 전력, Thermal Design Power) 보기 file JaeSoo 2012.11.16 5625
1139 하드웨어 CPU의 제원표 알아보기 file JaeSoo 2012.11.16 5109
1138 건강 코뼈가 휘면 비염에 걸리나요? - 비중격만곡증과 비염 file JaeSoo 2012.11.15 5640
1137 건강 몸에 비듬이 많이 생기거든요. file JaeSoo 2012.11.15 4151
Board Pagination Prev 1 ... 62 63 64 65 66 67 68 69 70 71 ... 124 Next
/ 124


■ 즐겨찾기 - 가족
JAESOO's HOMEPAGE YOUNGAE's HOMEPAGE 장여은 홈페이지 장여희 홈페이지 장여원 홈페이지

■ 즐겨찾기 - 업무
알리카페 홀릭 숭실대 컴퓨터 통신연구실 (서창진) 말레이시아 KL Sentral 한국인 GuestHouse

■ 즐겨찾기 - 취미
어드민아이디 유에코 사랑회 아스가르드 좋은사람/나쁜사람 JServer.kr 제이서버 메타블로그 재수 티스토리

■ 즐겨찾기 - 강의, 커뮤니티
재수 강의 홈페이지 한소리 VTMODE.COM 숭실대 인공지능학과 숭실대 통신연구실

PageViews   Today : 904   Yesterday : 2,704   Total : 61,337,336  /  Counter Status   Today : 381   Yesterday : 960   Total : 3,304,961
Site Info   Member : 1,394  /  Total documents : 7,152   New documents : 0  /  Total comments : 514

design by by JAESOO.com

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내

이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소