Sometimes you want code blocks to execute only under certain conditions. For example, if a number is sufficiently high or a string contains a substring. Here we’ll look at if statements as a means to fulfilling this purpose.

These types of structures contain a few different elements:

  • The condition to be evaluated
  • The action if it evaluates to true
  • The action if it evaluates to false

There are variations of if statements:

  1. If statement
  2. If…else statement
  3. If… else if… else
  4. Nest if statements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s