Skip to main content

Loops

Loops repeat a set of blocks. Use them to count, to walk through a list, or to keep going until something changes.

The Loops category

The loop blocks​

repeat ... times​

The repeat block

Runs the blocks inside a fixed number of times.

repeat while / until​

The while block

Keeps running for as long as a condition is true, or until it becomes true. Switch between the two with the dropdown.

warning

A while loop whose condition never becomes false will hang your bot. Make sure something inside the loop changes the value the condition depends on.

count with​

The count block

Counts from one number to another, storing the current number in a variable. count with i from 1 to 10 by 1 gives you 1, 2, 3 and so on up to 10. Change the by value to count in steps, or make it negative to count down.

for each item in list​

The for each block

Runs once for every item in a list, putting the current item in a variable. This is the loop you want whenever you already have a list, such as the results of a database query or a list you built with the Lists blocks.

break out of loop​

The break block

Stops the loop early. Switch the dropdown to continue with next iteration to skip the rest of this pass and move on to the next one.

Discord loops live elsewhere​

DisFuse also has loops built for specific Discord objects, and they are in the category they belong to rather than here:

LoopCategory
For each member in a serverMembers
For each channel in a serverChannels
For each role in a server, and for each member with a roleRoles
For each server the bot is inServer
For each emoji or sticker in a serverEmojis, Stickers
For each inviteInvites
For each reaction on a messageMessage
For each file in a folderFiles

Use those rather than fetching a list and looping over it yourself. They handle the fetching for you.

tip

Loops that touch Discord are slow, because each pass is a request over the network. Looping over 5,000 members to find one of them will take a long time and may hit Discord's rate limits. If you can look the thing up directly, do that instead.