What is an if statement?

devdrake0

Si

Posted on May 31, 2019

What is an if statement?

An if statement, in programming terms, is a condition statement. When the condition is satisfied, it performs an action (or block of code)

What is an if statement?

If you ever asked yourself how apps or websites decide if a view should be shown; chances are there is an if statement.

An if statement is the most basic method to decide if a certain block of code should be executed or not based on a condition.

You can liken it to making a simple decision: "Should I go outside and take a walk?"

If the answer to this is Yes you have to put on your shoes (that's the block of code that needs to be executed if the condition is met). So in programmatic terms, it could look something like this:

if (takeWalkOutside) {
    // put on your shoes
}
Enter fullscreen mode Exit fullscreen mode

If you decide not to go outside (the takeWalkOutside condition is not met), the action of putting on your shoes (the code inside the if statement) is skipped.

💖 💪 🙅 🚩
devdrake0
Si

Posted on May 31, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What is an else statement?
beginners What is an else statement?

May 31, 2019

What is a switch statement?
beginners What is a switch statement?

May 31, 2019

What are comments?
beginners What are comments?

May 31, 2019

What is pseudocode?
beginners What is pseudocode?

May 31, 2019

What is testing?
beginners What is testing?

May 31, 2019