Menu
CoddyTech

Continue

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 46 of 92.

The continue statement skips the rest of the current iteration and jumps to the next one. Unlike break, the loop keeps running.

for i in range(3, 9):
	if i == 5:
		continue
	print(i)

The loop goes through the numbers from 3 to 8. When i is 5, continue skips print(i), so 5 is missing from the output:

3
4
6
7
8

In a while loop, update the variable before continue. A continue above the update would skip it, and the condition would never change:

var i := 0
while i < 5:
	i += 1
	if i == 3:
		continue
	print(i)

This prints 1, 2, 4 and 5.

challenge icon

Challenge

Easy

The program prints the numbers from 1 to 20.

Add an if statement with continue inside the loop, so the program prints only the even numbers (2, 4, 6, ... 20), one per line.

Try it yourself

extends Node

func _ready():
	for i in range(1, 21):
		print(i)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online GDScript compiler