Replace a FOR loop into an infinite one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danielkun
    New Member
    • Dec 2006
    • 3

    Replace a FOR loop into an infinite one

    I'm building a simple slideshow and would like to exchange the FOR loop below into an infinite loop that will start over with picure 1 when picture 5 has been shown.

    Im still new to C and I hope someone can help me

    Code:
    char *inputFile[] = {"/1.jpg","/2.png","/3.jpg","/4.png","/5.png",NULL};
    
    for(i=0; NULL != inputFile[i]; i++) {
    
    sprintf(max_image_file_path, DATADIR"%s", inputFile[i]);
    
    ... some code
    
    }
    Making the infinite loop isnt very hard but I dont know how to access the array and start over when I reached nr 5.

    Thank you!
  • danielkun
    New Member
    • Dec 2006
    • 3

    #2
    I placed the FOR loop inside a while(1) loop and solved the problem but are there any other (better) ways?

    Comment

    • diwakar09
      New Member
      • Sep 2007
      • 39

      #3
      Originally posted by danielkun
      I'm building a simple slideshow and would like to exchange the FOR loop below into an infinite loop that will start over with picure 1 when picture 5 has been shown.

      Im still new to C and I hope someone can help me

      Code:
      char *inputFile[] = {"/1.jpg","/2.png","/3.jpg","/4.png","/5.png",NULL};
      
      for(i=0; NULL != inputFile[i]; i++) {
      
      sprintf(max_image_file_path, DATADIR"%s", inputFile[i]);
      
      ... some code
      
      }
      Making the infinite loop isnt very hard but I dont know how to access the array and start over when I reached nr 5.

      Thank you!
      yes you are right making for loop into infinite is not a big deal
      you can make it
      Code:
          int i = 0;
        for( i ; i < 6 ; i++)
      {
           ......
          if ( inputFile[i] == NULL )
             {   i = 0;
                  continue;
              }
      }
      may be this is not the proper code but you have to do some thing like this.
      I hope you got it the idea.

      otherwise you can find out the lenght of char *array and do some manipulation to make it infinite.

      Comment

      • mattmao
        New Member
        • Aug 2007
        • 121

        #4
        Hello.

        If you want to have an infinite for loop, try this:

        Code:
        for( ; ; )
                       {
                          //code block goes here
                       }

        Comment

        Working...