≡ 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.

Want Free Access to my Best Java Courses?

Alright, so if you’re read this far down the article, then you’re clearly interested in learning how to code. You can currently get access to my 2 best courses on Java for free for 30 days (then it’s just $10/month afterwards, or $97/year).

When you sign up you’ll receive login information to start learning about Java. If you decide you don’t like the courses, you can cancel at any time. If you decide you love the courses then you don’t have to do anything and you can stay subscribed for as long as you like for just $10/month or $97/year.

It’s like Netflix for coders!

Go ahead an click the button below to get started!

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.
{ 64 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.

  • Test Bank Economics May 5, 2017, 11:27 am

    Amazing issues here. I am very glad to peer your article. Thanks a
    lot and I’m looking forward to contact you. Will you kindly
    drop me a mail?

  • John Lardinois May 20, 2017, 10:48 pm

    I think one of the most important fundamental pieces of any programming language is a Function, which is technically a control structure.

    It is often thought of as a variable that stores a section of code, but actually it’s more of a symbolic link – when compiling, the linker goes through and links all of the function calls to their appropriate code lines like a web. So a function is technically a control structure saying, “jump to this line of code”. In machine language (which is what the code is converted to you compiling), it is literally written as, GOTO (go-to line x, y, z).

  • johny yes papa July 22, 2017, 7:25 pm

    Compatibility: Calls for iOS 7. or later.

  • Test Bank Accounting July 22, 2017, 9:52 pm

    An impressive share! I’ve just forwarded this onto a friend who was doing a little homework on this.
    And he actually bought me dinner because I discovered it for him…

    lol. So let me reword this…. Thank YOU for the meal!!
    But yeah, thanx for spending time to discuss this
    issue here on your internet site.

  • Ramesh July 25, 2017, 3:36 am

    wow. great info dear Trevor. I was searching for such site for a long time and finally got yours. thanks.

  • Lynell August 31, 2017, 11:37 am

    What’s up to all, the contents existing at this web page aare genuinely remarkable
    foor people experience, well, keep up the good work fellows.

  • Addcrazy.com September 17, 2017, 3:33 am

    o Plant your seeds with each season in mind, so that no matter what season it can be, you may will have flowers
    blooming within your garden. Perhaps you’ve got started thinking about NASCAR and therefore are looking for some ways to get involved with it.
    A simple call towards the local City Hall Offices or County Officials Buildings should aid
    these questions.

  • a business report September 17, 2017, 3:53 am

    Stick with what you’re doing, or find another and much
    better online strategy to exchange the classified ad strategy.
    Anyone can compose and write about any topic, from hobbies to political vies.
    This is a gesture of fine will in hopes that
    other bloggers can do exactly the same.

  • internet explorer bu September 17, 2017, 3:55 am

    Some website owners will be more frustrated
    about Google optimization than for other search engines.
    If it goes down, or they decide not to url to your site content
    for whatever reason, you are in trouble. – Add or remove a contact from your list with a date within the future
    – Good luck.

  • financement d'un projet September 17, 2017, 3:58 am

    So if that is insufficient to convince you that you’d be doing who you
    are a disservice by wanting to source your personal finance – well – you’re special.
    Beyond a forward thinking entry way painted red you may also make use of creating a simple, consistent distinct flowers and plants that outline the road from your
    front door on the street. 1 trillion economy and has been the single largest driver in the
    world requirement for imports of merchandise and services.

  • world news com September 17, 2017, 4:14 am

    Upcoming New Releases: Going with exactly the same concept above, if you have a friend in radio or are simply really ahead with the
    curve musically, you might create a site that lists and describes the upcoming new album
    releases. If one is careful to not offend, create or she could generate thousands of new readers.
    A blog writing service knows the best way to spark the interest
    for the services and products, that will drive more visitors and result
    in higher revenues for your business.

  • social news fb September 17, 2017, 4:26 am

    ” Not being a philosopher or even a physicist, I’m not planning to look into that subject on the internet, but I let you know that, from your marketing standpoint, the world wide web marketing effect on the business mentioned above would have been a big fat zero. In breaking news from The Age, it can be reported that this carbon tax will hit each and every Australian with a hefty price tag of $40,000 by 2050 coming to a massive $1 trillion hit to the Australian economy. Dabangg is often a buzz today, tomorrow it’ll be supervened by the Dhobighat something like that else.

  • rapid 7 blog September 17, 2017, 4:40 am

    Would making 8 or 10 thousand dollars monthly from a simple blog make
    positive changes to life. To see the complete
    impact these events are experiencing on the local Houston area market, we’ll need to hold
    back until in a few days, once the Houston Association of Realtors releases its March home sales results.
    Normally, these would contain dummy text to provide you an idea how the finished font side from the card you are creating.

  • Godwin October 11, 2017, 10:00 am

    quite understanding thanks bro

  • Hafis jimoh October 16, 2017, 8:36 am

    Hi i was watching the control structures video and a bit confused about calendar data type especially the .getinstance can you pls elaborate for me please thanks

  • Anonymous November 7, 2017, 10:30 pm

    After reading all that I think I’ll just click next.

  • Tobzil March 28, 2018, 9:45 pm

    Please I want learn how to program using a basic program language ,.,..so you can just give some easy steps to start

  • Putri Reduan June 4, 2018, 4:22 am

    Thank you! This post has been very helpful!

  • Flavio Carfagnini November 25, 2018, 5:08 am

    Hi Trevor!
    I started to program also thaks to you and when I first listen your podcast.
    So thanks for that!
    Well I’d like to ask you a specific question and hope you might enlight me.
    I’m building a battleship game in java using 3 classes to create the grid (10*10):grid,square and row
    I was wondering how can I create the inizial grid.so far I have managed to create the class square and populate it with an int which I called position using constructor, tostring method and get/set… So I did the same for the row but some how I got stuck.the row has inside the class square just to clarify.
    The question is..how should I create the grid ?
    I hope you’ll reply but if not I thank you for the inizial imput you gave me introducing this new world to me

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.