Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Loop variable post-execution

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 33
    Answer it

    Hey guys,

    Just  wondering if anyone can help. Given this statement: "Once you have completed executing a loop, the loop variable must be outside of the valid range of the condition", what does the latter part mean regarding the loop variable being outside the valid range? 

 1 Answer(s)

  • int i=0;
    for(int i=0;i<5;i++){
        //code goes here
    }

    Loop has 3 parts
    initialization
    condition
    increement

    flow goes this way
    initialization, checks the condition(above loop will check for i, If i is less than 5), increement and run the loop statement

    initialized with 0, check the condition(if i is still less than 5), increement i++(i=1), run the loop statement
    check the condition (if i is still less than 5), increement i++(i=2), run the loop statement
    check the condition (if i is still less than 5), increement i++(i=3), run the loop statement
    check the condition (if i is still less than 5), increement i++(i=4), run the loop statement
    check the condition (if i is still less than 5), increement i++(i=5), run the loop statement
    check the condition (if i is still less than 5)- No value of i has become 5 now, so looping process is finised

    And now, i(loop variable) is outside of the valid range of the condition, i.e value of i is not less than 5 now, it has become 5


    Hope it solves your query, Questions are always welcome.

    Cheers
    Happy Coding!!!!
     
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: