Essential Programming | Control Structures

栏目: IT技术 · 发布时间: 4年前

内容简介:If you want to start programming, I must admit that the outlook is not good: different operating systems, so many programming languages, and endless ways of reaching the same results. These are the type of situations that will make you either run away (as

The backbone of programs

Essential Programming | Control Structures

If you want to start programming, I must admit that the outlook is not good: different operating systems, so many programming languages, and endless ways of reaching the same results. These are the type of situations that will make you either run away (as fast and as far as you can, hoping you’ll never bump into programming again), or face the beast. If you decide to face it, then you won’t know where to start from, or how to handle it. You’ll only have questions and probably not even one answer, but you know what? This is a great way to start. Actually this is how I started programming. I believed that if I ever wanted to understand programs I had to answer the question of:

How do programs work, and how can you build them?

Certainly not a simple issue, but come on, harder questions have been answered, right? Take a look at Marvin Minsky. Minsky, who is considered one of the fathers of AI, wrote “The Society of Mind” to answer one of the most difficult questions of our time: what is the human mind, and how does it work? With a revolutionary perspective, Minsky suggested that our minds consist of the aggregation of small-minds (or more basic components) that have evolved to perform highly specific tasks. According to him, most of these tiny-minds lack the attributes we think of as intelligence and are severely limited, and can only reach feelings, thoughts or purposeful action through the interaction with other components.

This idea contains a powerful concept: complex matters can be thought as groups of simpler subjects, that can also be partitioned into more basic things, until you reach a proper understanding. If you think about it this way, any efficient system can be explained as a set of simpler functions that when put together perform in a way that reach superior results in comparison to their individual performances.

For this reason, if I wanted to understand computer programs (and learn how to make them) I needed to understand their building blocks. You see, when a program runs, the code is read by the computer line by line (from top to bottom, and from left to right), just like you would read a book. At some point, the program may reach a situation where it needs to make a decision such as jump to a different part of the program or re-run a certain piece again. These decisions that affect the flow of the program’s code are known as a Control Structures.

Control Structures can be considered as the building blocks of computer programs. They are commands that enable a program to “take decisions”, following one path or another. A program is usually not limited to a linear sequence of instructions since during its process it may bifurcate, repeat code or bypass sections. Control Structures are the blocks that analyze variables and choose directions in which to go based on given parameters.

The basic Control Structures in programming languages are:

  • Conditionals (or Selection): which are used to execute one or more statements if a condition is met.
  • Loops (or Iteration): which purpose is to repeat a statement a certain number of times or while a condition is fulfilled.

Now let’s take a look at each one of these concepts. Down below we will deep dive using R programming language (one of the mostly used languages for data science), but the same ideas and explanations apply to any other programming language.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

计算机程序设计艺术

计算机程序设计艺术

Donald E.Knuth / 苏运霖 / 机械工业出版社 / 2006-4 / 45.00元

《计算机程序设计艺术》(经典计算机科学著作最新版)(第1卷第1册双语版)更新了《计算机程序设计艺术,第1卷,基本算法》(第3版),并且最终将成为该书第4版的一部分。具体地说,它向程序员提供了盼望已久的MMIX,代替原来的MIX的一个以RISC为基础的计算机,并且描述了MMIX汇编语言。一起来看看 《计算机程序设计艺术》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具