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
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