EZ Programing Demos

Slow motion, step by step, animated demonstrations of basic computer programing techniques

Links to topics:

Current topic:

If, else

An if, else statement lets you take one of two paths. If the Boolean expression is true, then the true block of code executes. If, however, the Boolean statement is false, then the false block of code runs.

 Slow  Medium  Fast 
Click 'Run' to go.

Here is how an if, else statement works:

 

These if, else statements give you two paths of execution. When the Boolean expression is true, your program goes down one road, when it's false, your program goes down a different road.

In a simple if statement (with no else) when the Boolean expression is false, your program does not go down any road, nothing happens.

 

Here's a flowchart for this if, else demo:

 

In an imaginary computer language this could all look like so:

    
    printLine("Before if");
    
    if(2 < 3)
    {
      printLine("Boolean expression is true.");
    }
    else
    {
      printLine("Boolean expression is false.");
    }
    
    printLine("After if");
    

 

Suggested next article:

At EZ Math Movie

EZ Math Movie is a site that can help you experiment with and understand many topics in mathematics. Its main feature is an interactive animated (x, y) graph that you control with an actual programing language. There are many examples and tutorials, and EZ Math Movie is crossed referenced with both EZ Programing Demos and Zona Land Education.

 

Zona Land Education is a site with explanations and interactive diagrams covering many topics in physics and mathematics. Zona Land Education is cross referenced with EZ Math Movie, and it contains several animations that use EZ Math Movie's programing language.