Loops - C P P

For


  • All of the 3 conditions are optional, Also there can be multiple Variables in each
  • Flow
    • Goes Initialization
    • Check Condition, If True then go to Body
    • Goes to updating then again does previous step, This continues till Condition becomes false
  • Syntax
        for(initialization; condition; updation) {
            // statement
        }
        for(auto var1:variable) {
            // statement
        }
    

While


  • Syntax
        while(condition) {
            // statement
        }
    

Do While


  • Syntax
        do {
            // statement
        } while(condition);
    

Others


  • break => Terminate the current loop
  • continue => Skip to the next iteration of the loop
Share: