Skip to content
OfficialDonut edited this page Jan 2, 2022 · 3 revisions

If / Else / Else If Statements

If and else statements are used for decision logic. An if statement can be used alone or followed by an else / else if statement.

if (condition)
    do something if condition is true
if (condition)
    do something if condition is true
else
    do something if condition is false

if (condition-1)
    do something if condition-1 is true
else if (condition-2)
    do something if condition-1 is false and condition-2 is true
else
    do something if condition-1 and condition-2 are both false

Loops

Loops are a programming construct used for iteration. In Visual Bukkit there are three types of loops:

  • Number Loop
  • List Loop
  • While Loop

Number Loop

A number loop is used to iterate a certain number of times. Use the [VB] Loop Number block to get the loop number.

This code broadcasts the numbers from 0 to 4.

List Loop

A list loop is used to loop through each value in a list. Use the [VB] Loop Value block to get the current value of the loop.

This code loops through all online players and messages "hello!" to them.

While Loop

A while loop will continuously loop while the value in the <boolean> slot is true. Be careful not to create an infinite loop i.e. a loop that never stops (it will freeze your server).

This code loops while the value of the number variable is greater than 0. Once the variable reaches 0, the loop stops.

Other Loop Blocks

[VB] Stop Loop
Immediately stops the loop.

[VB] Continue Loop
Advances the loop to the next iteration.

VisualBukkit Discord: https://discord.gg/ugkvGpu

Clone this wiki locally