You are on page 1of 2

#include <iostream>

using namespace std;

void if_statement()
{
int x = 100;
if (x==100) cout << "x is 100" << endl;
}

void block_if_statement()
{
int x = 90;
if (x == 90)
{
cout << "x is ";
cout << x << endl;
}
}

void if_else(int x) {
if (x > 0)
cout << "x is positive" << endl;
else if (x < 0)
cout << "x is negative" << endl;
else
cout << "x is 0" << endl;
}

void whileloop()
{
int n = 10;

while (n>0) {
cout << n << ", ";
--n;
}

cout << "liftoff!\n";


}

void dowhile()
{
string str;
do {
cout << "Enter text: ";
getline (cin,str);
cout << "You entered: " << str << '\n';
} while (str != "goodbye");
}

void forloop()
{
for (int n=10; n>0; n--) {
cout << n << ", ";
}
cout << "liftoff!\n";
}

void rangeloop()
{
string str {"Hello!"};
for (char c : str) // char can be auto
{
cout << "[" << c << "]";
}
cout << '\n';
}

int main() {
if_statement();
block_if_statement();
if_else(1);
if_else(0);
if_else(-1);
whileloop();
forloop();
rangeloop();
}

You might also like