473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. char *inputFile[] = {"/1.jpg","/2.png","/3.jpg","/4.png","/5.png",NULL};
  2.  
  3. for(i=0; NULL != inputFile[i]; i++) {
  4.  
  5. sprintf(max_image_file_path, DATADIR"%s", inputFile[i]);
  6.  
  7. ... some code
  8.  
  9. }
  10.  
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!
Oct 10 '07 #1
3 1184
I placed the FOR loop inside a while(1) loop and solved the problem but are there any other (better) ways?
Oct 10 '07 #2
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

Expand|Select|Wrap|Line Numbers
  1. char *inputFile[] = {"/1.jpg","/2.png","/3.jpg","/4.png","/5.png",NULL};
  2.  
  3. for(i=0; NULL != inputFile[i]; i++) {
  4.  
  5. sprintf(max_image_file_path, DATADIR"%s", inputFile[i]);
  6.  
  7. ... some code
  8.  
  9. }
  10.  
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
Expand|Select|Wrap|Line Numbers
  1.     int i = 0;
  2.   for( i ; i < 6 ; i++)
  3. {
  4.      ......
  5.     if ( inputFile[i] == NULL )
  6.        {   i = 0;
  7.             continue;
  8.         }
  9. }
  10.  
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.
Oct 10 '07 #3
mattmao
121 100+
Hello.

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

Expand|Select|Wrap|Line Numbers
  1. for( ; ; )
  2.                {
  3.                   //code block goes here
  4.                }
Oct 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

36
by: Remi Villatel | last post by:
Hi there, There is always a "nice" way to do things in Python but this time I can't find one. What I'm trying to achieve is a conditionnal loop of which the condition test would be done at...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
5
by: mailpitches | last post by:
Hello, Is there any way to kill a Javascript infinite loop in Safari without force-quitting the browser? MP
4
by: LOPEZ GARCIA DE LOMANA, ADRIAN | last post by:
Hi all, I have a question with some code I'm writting: def main(): if option == 1: function_a()
10
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug....
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.