Tech Today Online

Go Back   Tech Today Online > Knowledge Base > Ask the Experts


Reply
 
LinkBack Thread Tools Display Modes
Old 09-19-2010, 01:32 PM   #1
Junior Member
 
Join Date: Sep 2010
Location: NC
Posts: 9
Roxy is on a distinguished road
Default Understanding Structure in Programming

I am a student majoring in Security. We are taking a programming class and I am not understanding the structure part at all. I know a structure is a basic unit of programming logic and each sturcture is one of the following: sequence, selection, and loop. What is an acceptable sturctured program though? The book gives all these illustrations with a big DON'T beside them, I am confused.

__________________
Members don't see ads in threads. Register your free account today and become a member on Tech Today Online, gaining access to posting privileges, contests, free plug-ins and other downloads, unlimited online storage for your photographs, reviews, free marketplace listings, and much more.
Roxy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-19-2010, 02:52 PM   #2
Senior Member
 
jcjacob's Avatar
 
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
jcjacob is on a distinguished road
Default

Structured programming enforces logical structure to make the program more efficient, easy to understand and maintain.

Large routines are broken down into smaller modules, and use of the GOTO statement is strongly discouraged

Let's say you have a program that reads a data file line by line, processes the data and prints it.

A structured program may look like this:

Open File
While (end of file is not reached)
read line of data
if (error condition)
Call Error routine
end program
end if
Call routine to process and print data
end while
end program

The same program that does not use structured programming might look like this:

Open file
LABEL1:
read line of file
if there was data
process data....
print data....
else
GOTO LABEL2
GOTO LABEL1
LABEL2:
exit program

Even in this simple example, you can see that it can easily become hard to follow, and the chance of introducing bugs increases as the lines of code increase.

I hope this helps answer you question. If not, post again and we'll give it another shot.
__________________
-John
jcjacob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-19-2010, 05:15 PM   #3
Junior Member
 
Join Date: Sep 2010
Location: NC
Posts: 9
Roxy is on a distinguished road
Default

Thanks John, That makes more sense than the book. Can you place a sequence within the true half of a dual alternative decision in a structured program? This is just one of the questions the book ask. I know that the dual alternative is used in the selection structure but can it be used in the sequence structure, since sequence you follow an action in a task in order? I really like the programming part that I have learned so far but not sure about structures.
Roxy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-19-2010, 06:53 PM   #4
Senior Member
 
jcjacob's Avatar
 
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
jcjacob is on a distinguished road
Default

Yes, you certainly can.

In a single alternative structure, if a condition is true, you do something, if it's false, you do nothing. In a dual-alternative basically means that if a condition is true, you do something, and if it's false, you do something else.

Within that IF construct, IF something is true, you might do some things. If it's false, you might do other things.

For example:

If today = Monday
do action 1
do action 2
do action 3
do action 4
do action 5
else
do action 6
do action 7
ENDIF
__________________
-John
jcjacob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-20-2010, 02:25 PM   #5
Junior Member
 
Join Date: Sep 2010
Location: NC
Posts: 9
Roxy is on a distinguished road
Default

Ok I see what you mean, so you could place decision within a loop and a loop within one of the steps in a sequence, right. I can understand the psuecode lots better than the flowcharts.
Thank you
Roxy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-20-2010, 02:59 PM   #6
Senior Member
 
jcjacob's Avatar
 
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
jcjacob is on a distinguished road
Default

yes, that's correct. You're getting it now

That's exactly why I used pseudocode for the examples....it's how I learned and it makes the most sense to me. I only used flowcharts to diagram the highest levels of functionality, much like an outline.
__________________
-John
jcjacob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-20-2010, 03:31 PM   #7
Junior Member
 
Join Date: Sep 2010
Location: NC
Posts: 9
Roxy is on a distinguished road
Default

You're right I do understand the examples you gave and my mind is wrapping around it better. Thank you so much.
Roxy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-22-2010, 11:50 AM   #8
Junior Member
 
Join Date: Sep 2010
Location: NC
Posts: 9
Roxy is on a distinguished road
Default

Thanks again John, I made a 95 on the quiz she threw at us yesterday.
Roxy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Old 09-22-2010, 03:11 PM   #9
Senior Member
 
jcjacob's Avatar
 
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
jcjacob is on a distinguished road
Default

That's awesome Roxy - you should be very proud of yourself. I'm happy for you!
__________________
-John
jcjacob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on Facebook
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:23 PM.