Teaching Newbies since 2014

kauress

  • Home
  • Javascript ❤
    • JavaScript
    • Node.js
  • WebDev Tuts
  • screencasts
  • Resources
  • VR & AR
  • Contact
  • Github
  • Twitter
  • YouTube
  • RSS
  • C++
You are here: Home / C++ / If-while statements in C++

January 7, 2020 by: Kauress

If-while statements in C++

If and while statements are pretty powerful as you can control when statement/statements of code are executed.
Syntax:
if(condition fulfilled){
do this;
} else{
do that
}
Example:
#include <iostream>
using namespace std;

int main() 
{

    // Set a equal to true here.
    bool a =  false;

    if (a) {
      cout << "Hooray! You made it into the if statement!" << "\n";
    } else{
        cout << "OOOOOPPSSS" << "\n";
}
}
While
While statements allow you to execute a block of code till/while a condition is true
Syntax:
while (condition){
do this;
}
Example:
Print out numbers 0-5 while i is less than or equal to <= 5
#include <iostream>
using namespace std;
int main(){
  int i = 0;
    while (i < 5) {
      cout << i << "\n";
      i++;
    }
}
C++ functions
Processing strings in C++ with

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2021 ·Kauress