Thread: why does the value in for loop reset?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    18

    why does the value in for loop reset?

    Code:
    #include <stdio.h>
    Code:
    
    
    int main()
    {
        int n;
        int i;
    
        for (n=1; n<=5; n++)
            {
        for (i=0; i<n; i++) // when the code reaches this loop and prints "*" i; will be +1 i.e i=1; and eventually i; will equal to n; and the code will jump out of the loop. What I dont understand is why i; resets after jumping out of the loop. When the loop starts again, i; equals to 0 instead of being 1 smaller than n;
            {
             printf("*");
            }
             printf("\n");
            }
    
    return0;
    }
    
    



    Im not trying to achieve a different result. I just need to know why i; goes back to 0 after jumping out of the loop.



    Last edited by mangekyou; 04-02-2019 at 06:23 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does auto_ptr::reset mean?
    By meili100 in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2008, 02:51 PM
  2. Trying to loop my program or reset it Dev c++
    By GameGenie in forum C++ Programming
    Replies: 8
    Last Post: 07-21-2005, 12:39 PM
  3. How to reset a pointer in a loop?
    By stillwell in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2004, 02:06 PM
  4. reset bios
    By rajesh23 in forum C Programming
    Replies: 5
    Last Post: 10-21-2003, 05:33 PM
  5. help why does cnt not reset to 1??
    By datainjector in forum C Programming
    Replies: 4
    Last Post: 07-17-2002, 12:56 AM

Tags for this Thread