Skip to content Skip to navigation

Connexions

You are here: Home » Content » Pseudocode Examples for Control Structures

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • OrangeGrove display tagshide tags

    This module is included inLens: Florida Orange Grove Textbooks
    By: Florida Orange GroveAs a part of collection:"Programming Fundamentals - A Modular Structured Approach using C++"

    Click the "OrangeGrove" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

  • Houston Community College

    This module is included in aLens by: Houston Community CollegeAs a part of collection:"Programming Fundamentals - A Modular Structured Approach using C++"

    Click the "Houston Community College" link to see all content affiliated with them.

  • Featured Content display tagshide tags

    This module is included inLens: Connexions Featured Content
    By: ConnexionsAs a part of collection:"Programming Fundamentals - A Modular Structured Approach using C++"

    Comments:

    "Programming Fundamentals - A Modular Structured Approach Using C++ is a new course written by Kenneth Leroy Busbee, a faculty member at Houston Community College. This text introduces students to […]"

    Click the "Featured Content" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Also in these lenses

  • SHN CNX Workshop display tagshide tags

    This module is included inLens: Stategic Horizon Network Workshop on Alternative Couseware -- Connexions Session
    By: ConnexionsAs a part of collection:"Programming Fundamentals - A Modular Structured Approach using C++"

    Comments:

    "Author, Ken Busbee, is a faculty member at Houston Community College and completed this textbook on programming after hearing about Connexions. His textbook is available in the Florida Orange […]"

    Click the "SHN CNX Workshop" link to see all content selected in this lens.

    Click the tag icon tag icon to display tags associated with this content.

  • CSE & eScience Content

    This module is included inLens: Computational Science and Engineering and eScience Content
    By: Jan E. OdegardAs a part of collection:"Programming Fundamentals - A Modular Structured Approach using C++"

    Click the "CSE & eScience Content" link to see all content selected in this lens.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

Pseudocode Examples for Control Structures

Module by: Kenneth Leroy Busbee. E-mail the author

User rating (How does the rating system work?)
Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

:
(0 ratings)

Summary: Pseudocode conventions and control structure examples of: if then else, case, while, for, do while and repeat until.

Overview

No standard for pseudocode syntax exists. However, there are some commonly followed conventions to help make pseudocode written by one programmer easily understood by another programmer. Most of these conventions follow two concepts:

  • Use indentation to show the action part of a control structure
  • Use an ending phrase word to end a control structure

The sequence control structure simply lists the lines of pseudocode. The concern is not with the sequence category but with selection and two of the iteration control structures. The following are commonly used ending phrase-words:

Table 1
Control Structure Ending Phrase Word
If then Else Endif
Case Endcase
While Endwhile
For Endfor

The Do While and Repeat Until iteration control structures don't need an ending phrase-word. We simply use the first word, then the action part, followed by the second word with the test expression. Here are some examples:

Selection Control Structures

Example 1: pseudocode: If then Else


If age > 17
  Display a message indicating you can vote.
Else
  Display a message indicating you can't vote.
Endif 

Example 2: pseudocode: Case


Case of age
  0 to 17   Display "You can't vote."
  18 to 64  Display "Your in your working years."
  65 +      Display "You should be retired."
Endcase 

Iteration (Repetition) Control Structures

Example 3: pseudocode: While


count assigned zero
While count < 5
  Display "I love computers!"
  Increment count
Endwhile 

Example 4: pseudocode: For


For x starts at 0, x < 5, increment x
  Display "Are we having fun?"
Endfor 

Example 5: pseudocode: Do While


count assigned five
Do
  Display "Blast off is soon!"
  Decrement count
While count > zero 

Example 6: pseudocode: Repeat Until


count assigned five
Repeat
  Display "Blast off is soon!"
  Decrement count
Until count < one 

Content actions

Give Feedback:

E-mail the module author | Rate module ( How does the rating system work?)

Rating system

Ratings

Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

How to rate a module

Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

(0 ratings)

Download:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.

| A lens (?)

Definition of a lens

Lenses

A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual Connexions member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks