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

Loops

A loop, as we know in common language, is circling the same path over and over again. In other words, if I am asked to fetch five ice creams from the ice cream store, and I can carry only one ice cream at a time, I will repeat the process of going to the ice cream shop to purchase ice cream five times. Correlating this with programming, if the same set of instructions need to be performed multiple times, then we put those instructions inside a loop.

A very basic loop is generally depicted as an iteration of a variable as many times as we want the instructions to be carried out.

Let's take an example:

Start the loop from one, until the loop has been repeated sixty times, adding a value of 1 to the loop:
Perform action

If you see the instructions being passed, there are three separate segments that are depicted in a loop:

  1. Start the loop from one: This means that the loop should start with a value of one.
  2. until the loop has been repeated sixty times: This means perform the same set of tasks until the loop has completed sixty turns of execution.
  3. adding a value of 1 to the loop: This means that we dictate that after completion of each round of loop, increment the loop count by 1.

The result will be the same action performed sixty times, until the loop count reaches sixty. Additionally, a loop can used to iterate through multiple values stored in a variable irrespective of whether it is an integer, string, or any other data type.

主站蜘蛛池模板: 武夷山市| 即墨市| 泾川县| 花垣县| 巴中市| 钟祥市| 定安县| 资阳市| 治县。| 松滋市| 锡林郭勒盟| 大同县| 洛浦县| 邻水| 万年县| 百色市| 梅河口市| 融水| 确山县| 澜沧| 苍溪县| 宁强县| 响水县| 孟连| 和林格尔县| 万盛区| 青海省| 连云港市| 华宁县| 托里县| 台江县| 深水埗区| 绍兴县| 丰都县| 芒康县| 临城县| 崇文区| 乐东| 息烽县| 库尔勒市| 贵港市|