Skip to main content

Posts

C++ Loops (For, While and Do while)

                                                   The for statement The C++ for statement has the following form: Syntax: for  (expression1;Condition;expression2) statement; for  (expression1;Condition;expression2) { block of statements } expression1 initialises; expression2 is the terminate test; expression3 is the modifier (which may be more than just simple increment); NOTE: C/C++ basically treats for statements as while type loops For loop example program: /* Example Program For for Loop In C++ Programming Language */ // Header Files #include<iostream> using namespace std; //Main Function int main() { // Variable Declaration int x=3; //for loop for (x=3;x>0;x--) { cout<<"x="<<x<<endl; } //Main Function return Statement return 0; } Output: x=3 x=2 x=1                                    The while statement The while statement is similar to those used in other languages althou
Recent posts

Conditional structure: if and else

                                                 Conditional structure: if and else The if statement executes based test expression inside the braces. If statement expression is to true, If body statements are executed and Else body statements are skipped. If statement expression is to false If body statements are skipped and Else body statements are executed. Simply, Block will execute based on If the condition is true or not. IF conditional statement is a feature of this programming language which performs different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch prediction, this is always achieved by selectively altering the control flow based on some condition. if and else Syntax if (expression) // Body will execute if expression is true or non-zero { //If Body statements }else { //Else Body statements } if and else Syntax Example for example, In c if (i == 3) { doSome

C++ Operators

                                                               Operators Once introduced to variables and constants, we can begin to operate with them by using operators. What follows is a complete list of operators. At this point, it is likely not necessary to know all of them, but they are all listed here to also serve as reference. Assignment operator (=) The assignment operator assigns a value to a variable.   x = 5; This statement assigns the integer value  5  to the variable  x . The assignment operation always takes place from right to left, and never the other way around:   x = y; This statement assigns to variable  x  the value contained in variable  y . The value of  x  at the moment this statement is executed is lost and replaced by the value of  y . Consider also that we are only assigning the value of  y  to  x  at the moment of the assignment operation. Therefore, if  y changes at a later moment, it will not affect the new value taken by  x . For exampl