หน้าเว็บ

2553-09-04

HOME WORK 100903

WHATARE THE THREE BASIC PROGRAMMING CONTROL STRUCTUSE ?

-Beginners can find Programming very confusing, Just like any other subject, there are a lot of new concepts to understand and lots of new terminology to learn. One of the most basic concepts in programming is control structures. There are three control structures and all programmers must learn what they are and how they can be used.These three basic structures can be used to develop any kind of program and they are explained below.

 
SEQUENTIAL PROGRAMMING
-The most straightforward control structure is the sequence. A list of what to do, step by step.


Example
1.do the first thing
2.do the next thing
3.do another thing

 
IN PSEUDOCODE
- Declare a variable called count
- Set count to 1
- Write out the value of count

 
REPETITION IN PROGRAMMING
-Repetition is also called iteration and is used when something is repeated over and over again, so anything where the program goes round in a loop. Typically programmed using code such as WHILE, REPEAT and FOR statements.


Example
1.Do the first thing
2.While (some condition is TRUE)
3.Do b
4.Do c
5.Do the next thing

IN PSEUDOCODE

- Set count to 0

- WHILE (there are items in a pile)
- Increase count by 1
- Write out the number of items
Another example to write out numbers 1 to 10
- FOR count = 1 to 10
- Write out count
- Write out ‘finished’


NOTE: a FOR loop is used when it is known exactly how many times to go round the loop
-Selection in Programming : Making Decisions
-Selection is used to make a decision to go down one path or another, often programmed using code such as an IF statement, or a CASE statement.


Example: To Pack my bag for work
1.Pack my PC

2.Pack my money
3.If it's raining
4.Pack my coat

IN PSEUDOCODE
- Work out total cost
- If (total cost > £10) THEN
- Write out ‘no delivery charge’
- ELSE
- Write out ‘£5 delivery charge’
- Write out ‘thankyou’

Another example using a CASE
- Write out the day
- CASE (day)
- Monday: write out ‘first working day of the week’
- Friday: write out ‘last working day of the week’
- Saturday: write out ‘the first day of the weekend’
- Sunday: write out ‘the second day of the weekend’

ENDCASE

- Sometimes there is confusion between the Repetition and Selection statements, as both use a condition. A condition is a test, resulting in true or false. One way of describing the difference is that when making a selection, the condition is only ever tested once. When used in repetition, the condition is tested a number of times, every time the program decides whether to loop.


- Beginners who take the time to learn the basic building blocks of programming will find coding in new languages easier and developing computer programs requires an understanding of the three basic control structures outlined above.


ไม่มีความคิดเห็น:

แสดงความคิดเห็น