Introduction to Computer Programming - part 5

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
ยท@humateยท
0.000 HBD
Introduction to Computer Programming - part 5
![enter image description here](https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drcG3vrppf3JtWrsGUfp8VkX29tCq_1680x8400)


----------


----------


## INTRODUCTION TO PROGRAMMING

I am collating my study notes as part of my education into Computer Programming. In an attempt to increase and improve my own learning, and to help others also (learn by teaching) I will be sharing my notes, as neatly presented as possible, for others to follow along with if they so wish. This is Lesson 5's notes.


----------


EARLIER LESSONS

[Lesson 1 Notes](https://steemit.com/education/@humate/introduction-to-computer-programming)
[Lesson 2 Notes](https://steemit.com/education/@humate/introduction-to-computer-programming-part-2)
[Lesson 3 Notes](https://steemit.com/education/@humate/introduction-to-computer-programming-part-3)
[Lesson 4 Notes](https://steemit.com/education/@humate/introduction-to-computer-programming-part-4)


----------
![enter image description here](https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drtM9Qos9WMkJj6w1DoVNDSLa3C2C_1680x8400)

----------

### INTRODUCTION TO COMPUTER PROGRAMMING โ€“ STUDY NOTES
**LESSON 5**


----------


**CONTROL FLOW**

Control Flow = creating an order in which statements will be executed in a program.

We touched briefly on **Control Flow** in lesson 4 where we discussed **Conditional Statements**. In this lesson we are looking at **Loops**.

Loops = a loop has a condition, and so long as that condition is true, the code will continue to run. When it become false then the code will end.

LINK: [Control Flow](https://en.wikipedia.org/wiki/Control_flow)


----------


**While Loop**

    initialise
    while (true){
    	do this
    	increment/decrement
    }
    more code

![](https://s19.postimg.org/alf68sy4j/While_1.jpg)

The above example prints out a line (I will be good in class) 50 times. The code checks that `X` is less than or equal to 50, and so long as that is true then the statement gets printed. When the code becomes false `(x > 50)` then the code will exit the loop.


----------


**Do-while Loop**

    initialise
    do {
    	do this
    	increment/decrement
    }
    while (true)
    more code

The difference between the *Do-While Loop* and the *While Loop* is that the *Do-While Loop* will be executed at least once, whereas the *While-Loop* contains the possibility that the code wont get run at all.

![enter image description here](https://s19.postimg.org/v5k07a65v/Do-_While_1.jpg)

The example is similar code to the above, but has been written as a *Do-While Loop*, and had `X` changed to 100. This makes the *While* statement false. This example is to illustrate that the code still prints out once (see line at bottom of screenshot that says '100: I will be good in class'.)


----------


**For Loop**

    for (initialisation; condition; increment/decrement){
    	statement;
    }
    more code

The *For Loop* puts everything into the brackets and determines if it's true before running the statement.

![enter image description here](https://s19.postimg.org/xzn5kq0mb/For_1.jpg)


----------


**Jump Statements**

**Break** = used to immediately jump out of a loop block.

![enter image description here](https://s19.postimg.org/9vwdwf2pv/Break_1.jpg)

The above example runs the loop, and then forces the loop to stop when `X==10`. At that point it is now outside the loop code.

**Continue** = skips the rest of a loop and jumps back to the top of the loop.

![enter image description here](https://s19.postimg.org/8tm7dvrmb/Continue_1.jpg)

In the above example the *If Statement* is true if the number is odd. `(X%2 == 1)` is true if the number is odd, and this causes the *Continue Statement* to run, causing the odd number not to print (instead the loop continues back to the top), and the loop starts again from the last (non-printed) number. In other words, this loop will print the even numbers, and skip the odd numbers. 

----------

**RECAP OF EARLIER LESSONS**

In **Lesson 1** we briefly looked at:

- What is a programming language?
- Language Types โ€“ especially HIGH Level and LOW Level.
- Compiled vs Interpreted Languages
- Data Types: Strongly Typed vs Weakly Typed Languages.
- Data Types: The most common data types (characters, integers, floating-point, fixed-point, boolean, reference).

In **Lesson 2** we looked briefly looked at:

- Variables
- Constants

These both flow on from Data Types and work with these.

In **Lesson 3** we looked briefly at:

- Operators

Used to allow operations (such as multiplication) to be performed on variables or constants.

In **Lesson 4** we looked briefly at:

- Conditional Statements

*If*, *If-Else*, *If-Then* Statements, which are used to control the flow of a program.



----------

![enter image description here](https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5dsT9d5jbweoK8z1LMpCpf62x6uPhp_1680x8400)

----------

**FURTHER DATA**

[cpp.sh](cpp.sh) - C++ shell website
Scratchpad - Shift + F4 on Firefox - Javascript shell
[Dev C++](https://sourceforge.net/projects/orwelldevcpp/) - A free, portable, fast and simple C/C++ IDE
[Code::Blocks](http://www.codeblocks.org/) - A free C, C++ and Fortran IDE
[Ideone](https://ideone.com/) - an online compiler and debugging tool which allows youto compile source code and execute it online in more than 60 programming languages.


----------

My Posts

[Introduction From a Newbie Programmer](https://steemit.com/introduceyourself/@humate/introduction-from-a-newbie-programmer) and [Intro - part 2](https://steemit.com/introduceyourself/@humate/my-introduction-part-2)
[Introduction to Computer Programming - part 1](https://steemit.com/education/@humate/introduction-to-computer-programming) (Lesson 1)
[Introduction to Computer Programming - part 2](https://steemit.com/education/@humate/introduction-to-computer-programming-part-2) (Lesson 2)
[Introduction to Computer Programming - part 3](https://steemit.com/education/@humate/introduction-to-computer-programming-part-3) (Lesson 3)
[Introduction to Computer Programming - part 4](https://steemit.com/education/@humate/introduction-to-computer-programming-part-4) (Lesson 4)


----------


Images from unsplash.com, except code screenshots, which are my own.

I welcome new [followers](https://steemit.com/@humate), and thank you for your upvotes and comments.
๐Ÿ‘ , , , , , , , , , , , , ,