For/While Loops - A Sorely Needed Mechanism

For those who know how to code, you should know what a for/while loop is.

For those who don’t, it’s basically a loop that continues repeating until either a certain condition is met (while loop), or until it iterates through something some amount of times (for loop).

They’re incredibly useful for any sort of code-like mechanism, and are almost necessary for a number of systems. For some reason, however, we haven’t actually made a guide on this yet. (I’m still really surprised we didn’t have these a long time ago)

The basic idea is this: we run a task, check if a certain condition is fulfilled, if not, we run it again.

We can actually do this with just this incredibly basic system:

SO HOW DO WE DO IT?

The trigger is the triggering thing. We can also substitute a counter in there instead if we don’t want any delay.

The counter can check for a property or item amount or something. Let’s say we’re using hooked property A. A starts at 10. The counter checks to see if A is above 0. When it is above 0, it will bounce the signal back to the trigger, along with decrementing the property’s hook. It then repeats 10 times, wow!

That’s literally it.
This is insane.
If you’ve ever decided against something because you didn’t have a for loop, time to reconsider!

21 Likes

no responses or likes in an hour is crazy lol

4 Likes

You do deserve better.

3 Likes

What is there to say lol

3 Likes

This guide is actually helpful. Thanks @Shdwy

(looks like you’re having a good day today)

2 Likes

Great guide! Loops are so useful for everything. Trigger clocks, super fast speed, etc., etc. Loops have almost endless possibilities! I’m using them right now for my Blackhole simulator in my game! You’re right shdwy, more people should use this. Also, likewise, I’m surprised that none of the coders, including getrithekd haven’t made a guide on this.

5 Likes

Because it was thought to be impossible.

1 Like

But it isn’t though. Blizzy made a guide utilizing this and so did shdwy in a previous one on why repeaters are trash. I guess not many people know how good and amazing the trigger is.

5 Likes

I would use a counter to make this extra cool and make it support looping through any number of times. Expect a flurry counter-related guides soon!

3 Likes

Oh boy…

Hey shdwy I stumbled across this:

2 Likes

bump because important (and spam shdwys notifs ahaha)

Huh what did I do haha

@PotionMaster it pinged me and i see you so go rejoin us pls
this happened with cool too lmao
OMG I CAN EDIT THESE?!?! -DannyStarf

bump -slim
BUMP- NPC_da_CPU

3 Likes

At the top, it says that while loops continue until a condition is met, and a for loop repeats something a set amount of time, but when I did JavaScript, they both repeated something until a condition was met, but they were just set up differently.
For while loops, they were set up kind of like this:
variable starting point
while (condition) {
repeat this;
changing the variable by this every time;
}
And for loops like this:
for (variable starting point, condition, change) {
what you want to do;
}
But, you know, in proper coding. (By condition I’m referring to when it stops repeating, for instance, if text is moving down, it would be at what y it stops repeating)

2 Likes

Sorry if that’s really unclear. There’s nothing wrong w/ the mechanism, it’s just a technicality that I just want to clear up for myself.