One may also sort the clothes according to the season or according to its colours. But no matter which way they choose to accomplish the task, the task itself can be ordered in a sequence.
The sequence may look something like this:. Empty the wardrobe. Fold the clothes. Arrange it into piles. Put the piles back into the wardrobe. The task is completed. By following this sequence, anyone can achieve the task. This idea is the basic principle behind sequence programming. What it effectively means is to break up a given task into an order or sequence of smaller tasks. Completing every small task or job in effect helps in completing the larger task. A sequence in programming refers to an ordered set of instructions or tasks.
The order is key here. If you follow the wrong order, then the task cannot be achieved, or you may get ambiguous results. Now that the definition of sequence is clear to you, let's go through another example of sequence. Algorithms are fundamental to sequences in programming, and they describe in detail how any task is to be achieved in a step-by-step ordered manner.
Algorithms can also be said to be a series of steps taken to achieve a given task. Computers rely heavily on algorithms to do useful work. Computers can neither function with intuitive knowledge, nor do they have their own intelligence to make decisions. The project that has been assigned to you is to build a flower garden.
The area of land is marked out for you, and all you have to do is start planting. In programming, sequence is a basic algorithm: A set of logical steps carried out in order. Computers need instructions in the form of an algorithm in order to complete a desired task, and this algorithm must have the correct order of steps, or sequence.
Example: We can relate sequence to our everyday lives. If we want to make a delicious, peanut butter and jelly sandwich, we need to follow multiple steps in a logical order. We would begin by gathering our ingredients, getting a knife, spreading the peanut butter, spreading the jelly, and so forth.
If we wanted a robot to make a peanut butter and jelly sandwich for us, we would need to make sure we gave the robot instructions in the correct sequence to avoid missing a step, not having all the ingredients we need, or ending up with an inside-out sandwich. Application : In programming, computers can only carry out tasks that are in the correct sequence.
But if we were only limited to Sequence our programs would be very limited indeed. We have to have a way to make decisions based on certain conditions. See the selection, we are selecting which operations to execute depending on what the value of age is. Pretty simple and useful too! Notice that on line 10 we added an if statement.
Notice how we combined Sequence and Selection to make our program more useful. But, suppose there are 3 voters and we would like to ask each of them what their age is.
We could copy and paste the code 3 times, right? Sure, but if we had voters the program would grow very large and become very hard to follow and change. We can use a loop to iterate 3 times. Programming languages all allow Iteration and many provide multiple ways to iterate.
But we now added a new operation on line 7 that tells the program to count from 1 to 3 and execute everything from lines that many times. Pretty cool! Now our program is using Sequence to provide the order in which we execute our instructions. Selection to allow decisions to be made and Iteration to loop or repeat our instructions as many times as we need. Of course, there is much more to programming. As our problems grow larger and more complex, we need other elements to help us deal with the complexity.
Some of these elements are classes, methods, functions, threads, and many others. Ready to learn more? Specifically, can JavaScript collect and handle data from a user in a mobile environment.
Your email address will not be published. These 3 elements are: Sequence Selection Iteration Sure, many programming languages have many other complex features. So, what are these 3 elements all about?
0コメント