(C++) else
February 24, 2017 · View on GitHub
(C++) else
else is a Keyword to allow conditional program flow.else will always follow an if statement and is optional to it.
if ( /* condition */ ) { //Do this when condition is true } else { //Do this when condition is false }
Example
#include <iostream> int main() { //Draw a random number const int x = std::rand(); if (x % 2 == 0) { std::cout << " The value of " << x << " is even." << std::endl; } else { std::cout << " The value of " << x << " is odd." << std::endl; } }