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++
10 Answers
+ 22
while(true) {}
+ 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
+ 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.
+ 8
while(true) {
}
+ 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.
+ 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 .
+ 1
Thanks gyuzz
+ 1
for java it's...
while(true)
{
//enter your code here
}
- 1
in py...
while (1+8*7)==(100-43) :
print("ooh crap")
- 2
đđđđi did it for fun...