ID:161807
 
This is an infinite loop is it not? If yes, how can I kill it using break propperly?
mob
verb
Lol()
for(var/mob/M in world) // this is an infinite loop isn't it?
if(M.client)
M<<"[src] says: =D"
break // if I use break here, the loop will stop here and only the first found client will read the message. :(

// I heard that infinite loops can lead to a crash, and if this is true...well, no wonder the game crashes so much.


What would be a correct way to end the loop with every client reading the sent message? Thanks in advance.
That's not an infinite loop. You don't need to use <code>break</code> either. It will send that message to every player in the world that is an actual player once.
That is like a who verb.. In a weird way,
        LoL()
for(var/mob/M in world)
if(M.key) M<<"[src] says: =D"
usr<<"You LoL at everyone"

That's it. Who doesn't loops so... The usr<<"" might be the break, i dunno
In response to Blink182_98f
You don't need a break with for(). It already has a break, which is the maximum amount of mobs in the world. It will perform what follows for every mob in the world and then stop. Stuff that comes afterwards, such as the user output, would be returned after the loop is finished, not as a break.
Im not good with loops but the
for(var/mob/M in world

is not an infinite loops, its a quick little check
In response to Siientxx
Phew...what a relief lol. Thanks guys.
while() is a loop though isn't it? But it's ok since I broke them all down.
In response to Takoma
Just because something is a loop, doesn't mean it's an infinite loop. While() is a loop, correct.

        var/loop = 1
while(loop)
world <<"This is an infinite loop." // You won't even see this message!


            
var/loop = 1
while(loop)
world <<"This loop is finite (?) it only loops once."
loop = 0

        
var/loop = 0
while(loop < 5)
loop++
world <<"This loop will perform five times."


I realize now what a funny word loop is.