create account

Introduction to Computer Programming - part 5 by humate

View this thread on: hive.blogpeakd.comecency.com
· @humate ·
$1.50
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.
👍  , , , , , , , , , , , ,
properties (23)
authorhumate
permlinkintroduction-to-computer-programming-part-5
categoryeducation
json_metadata{"tags":["education","howto","steemiteducation","technology","teamaustralia"],"image":["https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drcG3vrppf3JtWrsGUfp8VkX29tCq_1680x8400","https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drtM9Qos9WMkJj6w1DoVNDSLa3C2C_1680x8400","https://s19.postimg.org/alf68sy4j/While_1.jpg","https://s19.postimg.org/v5k07a65v/Do-_While_1.jpg","https://s19.postimg.org/xzn5kq0mb/For_1.jpg","https://s19.postimg.org/9vwdwf2pv/Break_1.jpg","https://s19.postimg.org/8tm7dvrmb/Continue_1.jpg","https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5dsT9d5jbweoK8z1LMpCpf62x6uPhp_1680x8400"],"links":["https://steemit.com/education/@humate/introduction-to-computer-programming","https://steemit.com/education/@humate/introduction-to-computer-programming-part-2","https://steemit.com/education/@humate/introduction-to-computer-programming-part-3","https://steemit.com/education/@humate/introduction-to-computer-programming-part-4","https://en.wikipedia.org/wiki/Control_flow","cpp.sh","https://sourceforge.net/projects/orwelldevcpp/","http://www.codeblocks.org/","https://ideone.com/","https://steemit.com/introduceyourself/@humate/introduction-from-a-newbie-programmer","https://steemit.com/introduceyourself/@humate/my-introduction-part-2","https://steemit.com/@humate"],"app":"steemit/0.1","format":"markdown"}
created2018-01-27 02:40:03
last_update2018-01-27 02:40:03
depth0
children4
last_payout2018-02-03 02:40:03
cashout_time1969-12-31 23:59:59
total_payout_value1.286 HBD
curator_payout_value0.212 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,389
author_reputation107,931,380,458
root_title"Introduction to Computer Programming - part 5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,624,427
net_rshares171,767,353,618
author_curate_reward""
vote details (13)
@minnowsupport ·
<p>Congratulations!  This post has been upvoted from the communal account, @minnowsupport, by humate from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows.  Please find us at the <a href="https://discord.gg/HYj4yvw"> Peace, Abundance, and Liberty Network (PALnet) Discord Channel</a>.  It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.</p> <p>If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=102530.639667%20VESTS">50SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=205303.639667%20VESTS">100SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=514303.639667%20VESTS">250SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=1025303.639667%20VESTS">500SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=2053030.639667%20VESTS">1000SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&amp;delegatee=minnowsupport&amp;vesting_shares=10253030.639667%20VESTS">5000SP</a>. <br><strong>Be sure to leave at least 50SP undelegated on your account.</strong></p>
👍  
properties (23)
authorminnowsupport
permlinkre-introduction-to-computer-programming-part-5-20180201t095057
categoryeducation
json_metadata""
created2018-02-01 09:50:57
last_update2018-02-01 09:50:57
depth1
children0
last_payout2018-02-08 09:50:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,702
author_reputation148,902,805,319,183
root_title"Introduction to Computer Programming - part 5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id34,091,497
net_rshares756,347,704
author_curate_reward""
vote details (1)
@steemitboard ·
Congratulations @humate! You have received a personal award!

[![](https://steemitimages.com/70x70/http://steemitboard.com/@humate/birthday1.png)](http://steemitboard.com/@humate)  1 Year on Steemit
Click on the badge to view your own Board of Honor on SteemitBoard.

> By upvoting this notification, you can help all Steemit users. Learn how [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-humate-20180206t062817000z
categoryeducation
json_metadata{"image":["https://steemitboard.com/img/notifications.png"]}
created2018-02-06 06:28:18
last_update2018-02-06 06:28:18
depth1
children0
last_payout2018-02-13 06:28:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length431
author_reputation38,975,615,169,260
root_title"Introduction to Computer Programming - part 5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id35,325,544
net_rshares0
@zinzilon ·
hi i am studying programming as well, but i am a super newbie .... so can you please help me with writing functions please?
👍  
properties (23)
authorzinzilon
permlinkre-humate-introduction-to-computer-programming-part-5-20180127t024228375z
categoryeducation
json_metadata{"tags":["education"],"app":"steemit/0.1"}
created2018-01-27 02:42:06
last_update2018-01-27 02:42:06
depth1
children1
last_payout2018-02-03 02:42:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length123
author_reputation114,314,996,146
root_title"Introduction to Computer Programming - part 5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,624,763
net_rshares482,087,294
author_curate_reward""
vote details (1)
@humate ·
We're both super-newbies. I am sharing my notes as I study them. Study along with me and maybe you will learn about functions soon. After this introduction course I will be sharing my notes on a C++ course.

Functions are made up of the material I am sharing (Control Flow Statements etc), but the knowledge on how to write them efficiently needs to be learned. I am still learning that.
properties (22)
authorhumate
permlinkre-zinzilon-re-humate-introduction-to-computer-programming-part-5-20180127t024549952z
categoryeducation
json_metadata{"tags":["education"],"app":"steemit/0.1"}
created2018-01-27 02:45:54
last_update2018-01-27 02:45:54
depth2
children0
last_payout2018-02-03 02:45:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length387
author_reputation107,931,380,458
root_title"Introduction to Computer Programming - part 5"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,625,370
net_rshares0