HTML Blox

Providing the building blox of the web.

  • HTML Blox Home
  • Blog
    • Design
    • Flash
    • General
    • HTML
    • Javascript
    • PHP
    • Programming
    • Web Servers
  • Forums
  • Where to Start?
  • Lessons
    • CSS
    • Design
    • HTML
    • Javascript
    • Programming
  • References
    • HTML
  • Resources
  • About
  • Contact
  • Go Green!

Programming Lessons

  1. Lesson 1: The Basics
  2. Lesson 2: A Brief History of Computers
  3. Lesson 3: The Workings of Computers
  4. Lesson 4: A Brief History of Programming
  5. Lesson 5: High-Level vs. Low-Level
  6. Lesson 6: Compiled vs. Interpreted
  7. Lesson 7: Variables
  8. Lesson 8.1: Arithmetic and Operators - Decimal
  9. Lesson 8.2: Arithmetic and Operators - Integer and Boolean
  10. Lesson 9.1: Conditional Statements - The Basics
  11. Lesson 9.2: Conditional Statements - Branching Conditionals
  12. Lesson 10.1: Loops - The Basics
  13. Lesson 10.2: Types of Loop
  14. Lesson 11: Functions
  15. Lesson 12: Strings
  16. Lesson 13: Procedural vs. Object-Oriented

Programming Reference

  1. No reference yet.

Links

  • W3C HTML 4.01 Strict Compliant
  • W3C CSS 2.1 Compliant
  • Web Standards Group Member
  • Follow us on Twitter
  • Number Overflow - Free Advanced Scripts and Tutorials
  • Azure Ronin Web Design - Professional Web Design and Development
  • XML Sitemap
  • U Comment, I Follow

Feeds

  • RSS 2.0 Feed
  • RDF/RSS 1.0 Feed
  • RSS 0.9 Feed
  • Atom Feed

Lesson 9.1: Conditional Statements – The Basics

del.icio.us Digg Blinklist reddit

In our last lesson we took a look at the basic types of arithmetic available in most programming languages. In this lesson, we’re going to take a look at using conditional statements which will allow us to give our programs something more than a straight-down list of number crunching.

What are Conditional Statements?

Conditional statements are statements which control the flow of code based on conditions. In less convoluted terms, it’s how you control your code based on what’s going on in your program. They are also sometimes called “control statements” or “control structures”.

All conditions used by conditional state are boolean (true/false) in nature, though this isn’t always apparent at first glance. It will evaluate the condition, and if it is true it will perform an action. If it is false, it will not perform the action (though it may continue down a list of conditional statements and perform another action based on the same condition).

There are two types of conditional statements: branching statements and loops.

Branching Statements

Branching statements are named so because they “branch” based on the condition. The types included in this category are if, if…else, and switch statements. All of these will look at the condition and perform a single action (which is sometimes nothing) based on that condition.

Loops

Loops will “loop” through the code (meaning it will perform a section of code, then loop back to the top of the code and perform it again) while a condition is true. The foundation of many programs that run constantly (which is basically every program other than simple web pages) is a loop. The common types of loops are for, while, and do…while. Many languages also implement foreach and do…until conditional statements as well.


In the next section we’ll take a look at actually utilizing each of the branching conditions. After that, the next lesson will be all about loops.

If you haven’t yet, be sure to take a look at the arithmetic lessons, especially Boolean Arithmetic. It will benefit you when we start talking about making use of the Boolean arithmetic in our conditional statements.

Next Lesson: Lesson 9.2: Conditional Statements – Branching Conditionals

This entry was posted on Monday, November 9th, 2009 at 11:47 am and is filed under Programming Lessons. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Please Login or Register or fill out the following to leave a reply:

If you haven't posted an approved comment before, your comment will not show up until approved.

  • HTML Blox Home
  • Blog
  • Design Blog
  • Flash Blog
  • General Blog
  • HTML Blog
  • Javascript Blog
  • PHP Blog
  • Programming Blog
  • Web Servers Blog
  • Forums
  • Where to Start?
  • Lessons
  • CSS Lessons
  • Design Lessons
  • HTML Lessons
  • Javascript Lessons
  • Programming Lessons
  • References
  • HTMLReferences
  • About
  • Resources
  • Contact
  • Go Green!
  • Sitemap

Copyright © 2008 HTML Blox

Unless otherwise noted, all images created and copyright HTML Blox.

Operated by Azure Ronin Web Design