Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. /// 4. conditions and loops
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. signed main(){
  7.  
  8.     int a,b;
  9.  
  10.     cin >> a >> b;
  11.  
  12.     /* condition operators:
  13.         (==) equals to
  14.         (!=) not equals to
  15.         (>) more than
  16.         (<) less than
  17.         (>=) at least
  18.         (<=) at most
  19.  
  20.        logic operators:
  21.         (&&) and
  22.         (||) or
  23.         (!) not
  24.     */
  25.  
  26.     /// condition statements
  27.     if(a>b && a>=2){ // curly brackets
  28.  
  29.         // if the condition is true, do something
  30.  
  31.     } // End If
  32.     else{
  33.         // else, do the other thing
  34.     }
  35.  
  36.     /// loops
  37.     for(int i=0;i<=5;i++){ // For i As Integer = 0 To 5 Step 1
  38.         // do something
  39.         cout << i << endl;
  40.     }
  41.  
  42.     int i=10;
  43.     while(i>=0){ // Just like While loop in VB
  44.         // do something
  45.         cout << i << endl;
  46.         i--; // means i = i-1
  47.     }
  48.  
  49.     /// ** Don't forget to add ';' at the end of the statement **
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement