if / else
Try it yourself →Executes code based on a condition.
Syntax
if (condition) { } else { }Description
Condition in parentheses, blocks inside { }.
Example
#include <iostream>
using namespace std;
int main() {
int score = 75;
if (score >= 50) cout << "Passed" << endl;
else cout << "Failed" << endl;
return 0;
}Expected output
Passed
When to use?
Flow branching.