≡ Menu

The 5 Basic Concepts of any Programming Language – Concept #2

Hi everyone,

This is post #2 in a series of 5 posts about the 5 basic concepts of any programming language.  Here’s a breakdown again of those concepts:

  1. Variables
  2. Control Structures
  3. Data Structures
  4. Syntax
  5. Tools

We’ve already discussed what a variable is, so now let’s talk about control structures.  What on earth is a control structure!?  Wiki describes it as follows:

A control structure is a block of programming that analyzes variables and chooses a direction in which to go based on given parameters. The term flow control details the direction the program takes (which way program control “flows”). Hence it is the basic decision-making process in computing; flow control determines how a computer will respond when given certain conditions and parameters.

H’okay, so, that definition is obviously a bunch of technical terms that no beginner to programming would understand.  So let me try to describe it in more human terms.  When a program is running, the code is being read by the computer line by line (from top to bottom, and for the most part left to right), just like you would read a book.  This is known as the “code flow“, now as the code is being read from top to bottom, it may hit a point where it needs to make a decision, this decision could make the code jump to a completely different part of the program, or it could make it re-run a certain piece again, or just plain skip a bunch of code.  You could think of this process like if you were to read a choose your own adventure book, you get to page 4 of the book, and it says “if you want to do X, turn to page 14, if you want to do Y, turn to page 5″.  That decision that must be made by the reader is the same decision that the computer program must make, only the computer program has a strict set of rules to decide which direction to go (whereas if you were reading a book, it would be a subjective choice based on whomever is reading the book).  So, this decision that must be made, that will in turn effect the flow of code, is known as a control structure!

Okay, that doesn’t seem to be such a hard concept… a control structure is just a decision that the computer makes.  So then that begs the question, what is it using to base that decision on?  Well, it’s simply basing its decision on the variables that you give it!  Let me show you a simple example, here’s a piece of Java code:

if (yourAge < 20 && yourAge > 12)
  // you are a teenager
  // you are NOT a teenager

So, you can see above that we have a variable, and its name is yourAge, and we are comparing yourAge to 20 and 12, if you’re less than 20 AND you’re more than 12, then you must be a teenager (because you are between 13 and 19 years of age).  What will happen inside of this control structure, is that if the value assigned to the yourAge variable is between 13 and 19, then the code will do whatever is inside of the first segment (between those first two curly braces { } ), and it will skip whatever is inside of the second code segment (the second set of curly braces { } ).  And if you are NOT a teenager, then it will skip the first segment of code and it will execute whatever is inside of the second segment of code.

Let’s not worry too much about what the code looks like for the moment, as I’ll touch on how to write the code out properly in section #4 syntax.  The only concept you need to try and wrap your head around right now, is that there is a way in programming to ‘choose’ which lines of code to execute, and which lines of code to skip, and that will all depend on the state of the variables inside of your control structure.  When I say state of a variable, I just mean what value that variable has at any given moment, so if yourAge = 15, then the state of that variable is currently 15 (and thus, you’re a teenager).

You’ve now seen one control structure and I’ve tried to explain it as best I could.  This control structure is known as an if...else structure.  This is a very common control structure in programming, let me hit you with some other examples.  Here’s a while loop control structure:

while (yourAge < 18)
  // you are not an adult
  // so keep on growing up!

This while loop control structure is also very handy, its purpose is to execute code between those curly braces { } over and over and over until the condition becomes false.  Okay, so what’s the condition?  Well, the condition is between the round brackets ( ), and in this example it checks yourAge to see if you are less than 18.  So if you are less than 18, it will continuously execute the code inside the curly braces { }.  Now, if you were 18 or older before the while loop control structure is reached by the code flow, then it won’t execute ANY of the code inside of the curly braces { }.  It will just skip that code and continue on executing code below the while loop control structure.

The Best 7 Java Programming Resources

Alright, so if you’re read this far down the article, then you’re clearly interested in learning how to code. We actually have a free guide that outlines the best 7 resources for Java programmers.

When you sign up you’ll receive the guide immediately and you’ll also receive a few emails a week that will help you speed up your Java learning process so you can get up and running as fast as possible.

Go ahead an click the button below to get started!

CAREFUL! Don’t Push This Button If You’re Not Ready To FINALLY Learn How to Code

There are a few other examples of control structures in Java, but I don’t want to overwhelm you with them right now.  So instead I’ll sum up what we’ve learned today.

We’ve learned that code flows from top to bottom and for the most part left to right, just like a book.  We’ve learned that we can skip over certain code or execute certain parts of code over and over again, and this is all achieved by using different control structures.  These control structures are immensely important to programming, as they make the programs function properly.  For example, you wouldn’t want people to be able to login to your Facebook account if they enter the wrong password right?  Well, that’s why we use the if...else control structure, if the passwords match, then login, else show a “password is incorrect” screen.  So, without control structures, your program’s code would only flow in one way, and it would essentially only do one thing over and over again, which wouldn’t be very helpful.  Changing what the code does based on a variable is what makes programs useful to us all!

I hope I’ve cleared the mystery behind the term control structure, and I look forward to talking about our next subject, data structures!

Plenty of Ways to Learn

  • COMMUNITY – Learning with a community is the best way to ensure accountability and support when you need help. Coders’ Campus is a brand new community that is dedicated to new programmers like you!
  • BLOGS – If you feel like you enjoy the way this information is laid out in blog format, then I invite you to click on the “next” button below.
  • BOOKS – If you feel like you are better at learning from a book, then I invite you to check out my ebook via http://javapdf.org. This eBook is organized, and packed full of easy to follow tutorials and videos.
  • VIDEOS – If you feel like you prefer learning by watching Videos, then check out the Java Video Tutorials website. It’s full of fun and easy to follow video tutorials. So far the students enrolled in this video course have rated it 9.5/10!
  • PODCASTS – Finally, if you prefer to learn by just listening, then there’s also a podcast available on iTunes via How to Program with Java Podcast.

{ 40 comments… add one }

  • Tatia July 10, 2012, 3:31 pm

    So far very interesting and easy to understand.

  • Rene Besana July 13, 2012, 1:28 am

    while it is true that the computer reads your code top to bottom fashion, it is not true that it always reads it left to right. when it comes to an assignment statement it reads from right to left, i.e., right to left of the equal sign (assignment operator) because it has first to determine the rvalue which it assigns to the lvalue.

    • Trevor Page July 13, 2012, 1:31 am

      You are absolutely correct Rene, I will update my post, thank you for the clarification 🙂

  • Jeffery September 29, 2012, 11:03 am

    When I initially left a comment I appear to have clicked the -Notify
    me when new comments are added- checkbox and from now on each
    time a comment is added I get four emails with the same comment.
    There has to be a means you are able to remove me from that service?


  • joe December 18, 2012, 9:11 pm

    True programming beginner right here! And I’d say that this is one of the easiest to understand tutorials out there. Keep it up man.

  • Ashish January 4, 2013, 2:50 am

    Nice work buddy Ur posts are very helpfull….


  • yatendra January 6, 2013, 1:42 am

    really helpful …thnx bro!!

  • Henry Ratemo January 18, 2013, 3:02 am

    Hi, i am so grateful for your effort to enlighten me on the fields that i had little knowledge on kudos and together we can go far……….more lessons and more especially new adventures in the programming field with JAVA

  • Durim January 23, 2013, 5:21 am

    Thanks Travor!

    You are so cool and your explanation is GREAT and VERY CLEAN!!

  • Kabiru February 18, 2013, 11:43 am

    Hi, this is very interesting i now start learning java very easy pls., continues with nice work

  • Isis April 16, 2013, 5:43 pm

    Hi Trevor,

    thanks a lot for your information and hard work. In your opinion, do you think a person could work as a programmer if they only know Java? Should an individual learn, for example, 5 languages before trying to work as a computer programmer or software/network developer? Thanks for your input!!

    • Trevor Page April 17, 2013, 10:20 am

      I wouldn’t say that you would need to know 5 different languages, but if you’re relying on mostly Java knowledge, then I would also recommend learning SQL for use with databases. If you want to go one step further, then understanding the “front end” technologies will give you a leg up as well… these “front end” technologies would include HTML/CSS, JavaScript/jQuery and some sort of MVC framework for Java (like Spring or Struts).

      • Jonathan October 19, 2013, 9:39 pm

        New to your site, and finding it very helpful so far!
        Will you cover integrating Java with these other technologies?

  • mohamed January 13, 2014, 6:32 pm

    this is what I’m looking 4

  • vamsi February 11, 2014, 10:14 pm

    I lyk da way u explain things

  • Raed May 29, 2014, 3:42 pm

    Hello Trevor,
    i am a java programer from Iraq and i hear your Podcast and i like
    the way how do you explain things about java and sql wonderful excellent
    and wish the best for you take care.

    best Regards

    • Trevor Page May 30, 2014, 10:05 am

      Thanks Raed, I really appreciate you taking the time to leave that comment

  • Raed June 6, 2014, 8:40 am

    Hello Trevor,
    i think i found a mistake about SQL Inner Join the Query

    select * from author
    inner join book on
    author.author_id = book.book_id; <—– mistake

    shoul be

    select * from author
    inner join book on author.author_id = book.author_id;
    because the FK is author_id in Book-Table

    best Regards


    • Trevor Page June 6, 2014, 11:33 am


      Nice catch Raed… this is why I should copy/paste my SQL code directly from my TOAD for MySQL. When I write it out manually, there’s room for human error. In any case, I’ve updated the code in the post. Thanks for finding that 🙂

  • Raed June 6, 2014, 2:39 pm

    Hi Trevor,

    thanks alot you are willcome, it’s happen.
    accept my best wishes

  • Evan July 1, 2014, 8:47 am

    so far so good! i went to a camp to learn java and got absolutely nothing from it. here, i can actually understand what your saying, its been very helpful. thanks so much!

  • not a bird May 22, 2015, 6:18 am

    birds don’t exist

  • waheef khan June 29, 2015, 9:35 pm

    hi,sir i’m barely new to programming, once i heared from peoples about a lots of difficulties in programming, i mean i know programming isn’t a piece of cake for a beginner espescially, but they way u taught is really make me learn basics much easier. “thumbs up”. sorry for grammer mistakes.

  • Harnish Parmtrar July 7, 2015, 12:19 pm

    Hi Trevor ,
    I m in final year of my engineering,can you suggest me some unique topic for my final year project. please give me some ideas.
    And thanks for your all videos……..

  • lakshay August 2, 2015, 6:09 am

    Hello Sir..
    I am deeply intrested in programming, but was not able to move on because of proper guideline . I read the basic concepts of programming on this page . I found it the most comfortable, understandable and interesting so far. Would please suggest me how to carry on with my programming from now, to become an excellent coder!
    thanks alot.

  • chris September 7, 2015, 3:42 pm

    This is really great. The else…if control Structure is very understandable. But is there anything like if…else…then…if control structure?
    please explain with example.

  • Kevin a September 8, 2015, 11:03 pm

    Thanks for all of your work.

    Two things.

    Fix “enrol” to “enroll”.


    I’ve tried to subscribe to your entrepreneur podcast and it isn’t working for me. iTunes gives me an error.

    Would really appreciate any attention you could give to this.

    Anyway… Great Stuff!

  • EMMANUEL KUNENE February 3, 2016, 8:40 am

    Hi im new in programming just started with visual basic, can you assist me how to grasp fast in order to move on to JAVA

  • higinio May 12, 2016, 1:24 am

    Hi there!
    Great info here and I’m happy to know you are using STS for your java projects. I’m using STS with the Pivotal server, but when you finish a project (mvc with maven and jsp) how do you install your java web development, because I know how to do it in php, but I have no idea how to do it with java ? Thx a million!!!!

  • Eric Ngutu June 13, 2016, 4:32 am

    about the while lo.op control structure, what did you mean by ”It will just skip that code and continue on executing code below the while loop control structure.”
    Will it execute to a blank statement before it proceeds with the code flow?

  • Kartikah July 7, 2016, 2:37 pm

    It is a great tutorial.
    easy to understand.
    i was taking classes of java programming last year but i dropped the classes bcoz i was not able to understand, but now im completely able to understand.
    thank u so much trevor, U are Great

  • ravindra August 3, 2016, 10:48 am

    Sir thanks for all that u had given to me

  • omer farooq September 6, 2016, 2:35 am

    really helping.

  • MUNGERE SADAM September 20, 2016, 5:41 am

    Very good work

  • Derek Montaque September 27, 2016, 8:51 pm

    Hi Trevor,

    Thanks for these lessons. I am currently learning C and C++. Although this focuses on JAVA I definitely have a better understanding of the basics as I am new to the programming world. Your way of explanation is exactly what I needed. Makes my teachers seem they have no clue what they are teaching lol

    Keep up the great work!

  • Sarah March 23, 2017, 3:27 am

    What kind of differences can I expect in switching from Ruby to Javascript?

    I found Stack Overflow horrible about trying to understand what different operands are.

    They seem more focused on telling you the solution to a problem they do than giving you the tools are asking you to experiment with a solution-or what I like as the more artistic path.

Leave a Comment