官术网_书友最值得收藏!

Logic

Logic is the study of reasoning and when we add this to the control structures, they become algorithms.

Have you ever watered the plants using a water pipe or washed a car with it? How do you think it works?

The pipe guides the water from the water tap to the car. It makes sure optimum amount of water reaches the end of the pipe. A pipe is a control structure for water in this case. We will understand more about control structures in the next topic.

How does a control structure work?

Everything that we see around us, has a name. In a class, there are several students. When the teacher says I will give the prize to the best student. The student could be anyone in the class – Eric, Emily, Jonnathan, and so on.

We conclude, that the word student, is a variable.

Similarly, while starting to write code, we define a box, which can contain different values at different times, depending on the condition that we define. A control structure, defines the final value of the variables.

A precondition is the state of a variable before entering a control structure. In the gift wrapping example, the size of the gift determines the amount of gift wrapping paper you will use. Hence, it is a condition that you need to follow to successfully finish the task. In programming terms, such condition is called precondition. Similarly, a post condition is the state of the variable after exiting the control structure. And a variable, in code, is an alphabetic character, or a set of alphabetic characters, representing or storing a number, or a value. Some examples of variables are x, y, z, a, b, c, kitten, dog, robot

Let us analyze flow control by using traffic flow as a model. A vehicle is arriving at an intersection. Thus, the precondition is the vehicle is in motion. Suppose the traffic light at the intersection is red. The control structure must determine the proper course of action to assign to the vehicle.

Thus, upon exiting the control structure, the vehicle is stopped.

If you wonder where you learnt to wrap the gift, you would know that you learnt it by observing other people doing a similar task through your eyes. Since our microcontroller does not have eyes, we need to teach it to have a logical thinking using code.

The series of logical steps that lead to a solution is called algorithm as we saw in the previous task. Hence, all the instructions we give to a micro controller are in the form of an algorithm. A good algorithm solves the problem in a fast and efficient way.

Blocks of small algorithms form larger algorithms. But algorithm is just code! What will happen when you try to add sensors to your code? A combination of electronics and code can be called a system.

Logic is universal. Just like there can be multiple ways to fold the wrapping paper, there can be multiple ways to solve a problem too!

A micro controller takes the instructions only in certain languages. The instructions then go to a compiler that translates the code that we have written to the machine.

主站蜘蛛池模板: 甘德县| 勃利县| 乌兰县| 大埔县| 调兵山市| 武威市| 沿河| 包头市| 闻喜县| 怀来县| 德惠市| 和顺县| 五家渠市| 杂多县| 志丹县| 华蓥市| 筠连县| 绥宁县| 凌云县| 巨野县| 铅山县| 武城县| 凉城县| 湘西| 如东县| 双鸭山市| 桃园市| 孟州市| 浠水县| 襄汾县| 海南省| 阿拉善盟| 琼结县| 张北县| 木兰县| 湘阴县| 巧家县| 扎赉特旗| 洞头县| 隆林| 屯门区|