0

How can we make a while loop infinty loop

Please put answers i have an assignment to do and i want it for c++

7th Nov 2017, 2:23 PM
Ambareesh Chandrabhaskar
Ambareesh Chandrabhaskar - avatar
12 Answers
+ 22
while(true) {}
7th Nov 2017, 2:32 PM
Tashi N
Tashi N - avatar
+ 13
Not really @Ace below 4 methods for ruby #method 1 limited by stack level def infini puts infini end #method 2 not limited by anything actually loop do puts 'infini start' sleep(9) puts "I'm refreshed let's do it again'" sleep(2) puts "short nap, \n restart" end #method 3 while loop while(!false) puts 'whi...' end #method 4 until loop until(false) puts 'til..' end
7th Nov 2017, 6:03 PM
Lord Krishna
Lord Krishna - avatar
+ 9
EXAMPLE 1: while(true){ // code here } ^That creates an inf loop until you break the loop. You can also use variables and utilize them also if you need to break a loop by those means. EXAMPLE 2: boolean infLoop = true; while (infLoop == true){ // code here } ^Essentially, same as the above loop except you have a variable that you can switch to false if you want. Maybe you want the rest of the code to finish and then on the NEXT loop through it'll break at the beginning if you set it to false during the last iteration.
7th Nov 2017, 2:38 PM
AgentSmith
+ 8
while(true) { }
7th Nov 2017, 3:08 PM
qwerty
qwerty - avatar
+ 5
@Sayan That's kinda drawn out though, isn't it? You could just as easily put: while 1 == 1: print("ooh crap") 1 will always equal 1, so it's inf.
7th Nov 2017, 2:54 PM
AgentSmith
+ 4
Probably a lots of way to make a loop infinity . while(true) being the easiest one . int i = 2; while(i>1) { i++; } gives you an infinity loop as well . So lots of possiblities .
7th Nov 2017, 3:02 PM
Kash
Kash - avatar
+ 1
Thanks gyuzz
7th Nov 2017, 2:33 PM
Ambareesh Chandrabhaskar
Ambareesh Chandrabhaskar - avatar
+ 1
for java it's... while(true) { //enter your code here }
7th Nov 2017, 2:36 PM
Zexter
Zexter - avatar
- 1
in py... while (1+8*7)==(100-43) : print("ooh crap")
7th Nov 2017, 2:46 PM
sayan chandra
sayan chandra - avatar
- 2
😂😂😂😂i did it for fun...
7th Nov 2017, 2:56 PM
sayan chandra
sayan chandra - avatar