If Statement

Get introduced to the if statement in C++.

Introduction

Suppose you can buy a watch if you get at least $20 in an allowance. Otherwise, you cannot. In C++, how can we make a decision based on a condition?

widget

We can use an if statement to demonstrate this kind of behavior.

The if statement instructs a compiler to execute a particular block of code when the condition evaluates to true.

Syntax

The general syntax of an if statement consists of the if keyword followed by the round brackets ( ) ...