How to make infinite loop by using FOR LOOP ? Solved. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How to make infinite loop by using FOR LOOP ? Solved.

I can do it by WHILE LOOP only.

9th Feb 2020, 3:21 PM
Cp Chaudhary
Cp Chaudhary - avatar
21 Answers
+ 12
You can not directly do it with a for loop, because a for loop always loops over an iterable. The iterable, however, can be built in a way that it dishes out values forever. (EDIT: Diegos example shows one example of that sort of iterable.) Please look at this question from a month ago which is basically what you're asking for. https://www.sololearn.com/discuss/2132309/?ref=app
9th Feb 2020, 3:32 PM
HonFu
HonFu - avatar
+ 11
import itertools for i in itertools.count(): print(i) break # Remove this to create an infinite loop
9th Feb 2020, 3:30 PM
Diego
Diego - avatar
+ 11
Hello @Jacob A friendly reminder that the behavior you've exhibited on this thread thus far is inappropriate. To cite our Community Guidelines: "SoloLearn's policies are based on two key principles: - Posts by SoloLearn community members should be programming-related and aimed at helping individual learners and community members improve their programming skills by creating a respectful resource base. Posts may also focus on improving aspects of the platform and providing the community with improved content, whenever applicable. - Personal attacks or disparagement of other users or their content is not tolerated. Every community member should be respectful and considerate, and assume that other people are also trying to make SoloLearn a great development resource. This means respecting opposing or differing opinions, beliefs, and conclusions; making an effort to listen to and understand others with whom you may disagree; and encouraging others to also be welcoming and respectful." https://www.sololearn.com/Content-Creation-Guidelines/ Please note the number of occurrences of the word "respectful" in the above excerpt. I found the following replies to be noncompliant: - "i dont care what u think," - "~ swim ~ yea, STOP POSTING ABOUT UNRELATED TOPICS PLEASE AND THANK YOU" - "~ swim ~ i didnt know about caps lock, but i do know i wont get banned for this" Please remove your posts in a timely fashion or I will remove them for you. If you continue to behave in a noncompliant manner, moderators do have the power to ban you -- contrary to what you've expressed. Please take heed. Warmest regards, -- Janning SoloLearn Gold Moderator
10th Feb 2020, 6:16 PM
Janning⭐
Janning⭐ - avatar
+ 9
Mùķę§h⅔ yes I didn't read python that's why I deleted my answer as soon as I saw python.
9th Feb 2020, 3:36 PM
VEDANG
VEDANG - avatar
+ 9
Hello Everyone, As ~ swim ~ said: "Please learn to curb the urge to post unnecessarily. Read the question properly before posting." Irrelevant posts substantially lower the quality of information available in our forum. Therefore, as a moderator, I can clean up this thread by removing any replies I determine to be off-topic. If you have any doubts about this, please review our Community Guidelines at: https://www.sololearn.com/Content-Creation-Guidelines/ As it states: "If your content/post is not specifically on-topic, it can be deleted." In the meantime, please consider providing helpful/useful insights in thread(s) which may actually be relevant to what you wanted to share. You can practice using the search feature to find such threads. Happy coding! Best, -- Janning⭐ SoloLearn Gold Moderator
10th Feb 2020, 6:15 PM
Janning⭐
Janning⭐ - avatar
+ 4
Ok I got it
9th Feb 2020, 3:38 PM
Cp Chaudhary
Cp Chaudhary - avatar
+ 4
def lettersforever(): n = 0 while True: yield chr(n+97) n = (n+1)%26 for letter in lettersforever(): print(letter)
9th Feb 2020, 3:52 PM
HonFu
HonFu - avatar
+ 4
Same goes for 😈😈😈😈😈😈😈: This is about for loops, which have no conditions. Please read questions properly, and ideally also the formerly given answers!
9th Feb 2020, 5:26 PM
HonFu
HonFu - avatar
+ 4
It is not possible to make an infinite loop with for loop because it will iterates based on the number of elements in the sequence. Syntax for For loop: for variable in sequence Infinite loop is possible with while loop.
10th Feb 2020, 1:00 PM
Lavanya
Lavanya - avatar
+ 4
Thanks for everyone but really I not need any more answer.
10th Feb 2020, 4:05 PM
Cp Chaudhary
Cp Chaudhary - avatar
+ 3
Thanks
9th Feb 2020, 3:33 PM
Cp Chaudhary
Cp Chaudhary - avatar
+ 3
Cp Chaudhary, you can edit your question and write [solved] in front of the title. It might help... somewhat. 🙄 Also you can click the star in the lower left of your question, then you won't get any more notifications.
10th Feb 2020, 4:09 PM
HonFu
HonFu - avatar
+ 3
for( i=0; true; i++) { ... }
10th Feb 2020, 10:17 PM
🍂B. Eitan 🌵
🍂B. Eitan 🌵 - avatar
+ 2
Jacob Burgess, 'I don't know python'. So why not stop right there? What do you hope to achieve adding information that has no relation to the question?
9th Feb 2020, 10:20 PM
HonFu
HonFu - avatar
+ 1
X = [4,5,6,7] For i in x: counter =+ 1 print(x)
11th Feb 2020, 6:14 AM
Lukman Farhan Aden
Lukman Farhan Aden - avatar
+ 1
Infinite loop for(; ;) { }
11th Feb 2020, 8:38 AM
vamshi
vamshi - avatar
+ 1
for(I=1;I;I++) ; Here is infinite foor loop
11th Feb 2020, 2:17 PM
Amrit Sood
Amrit Sood - avatar
+ 1
Its very simple with c try out this https://code.sololearn.com/cJU8wnszxYSW/?ref=app
1st Apr 2020, 7:26 AM
stephen muganyizi
stephen muganyizi - avatar
0
Miss the condition inside and iterate it using increment operator,you will get infinite loop.
10th Feb 2020, 3:56 PM
shubham kumar
shubham kumar - avatar
0
for(;;)
11th Feb 2020, 1:24 PM
Jimoh Abdulrasheed