Difference between PASS and RETURN

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By henriquelalves
:warning: Old Version Published before Godot 3 was released.

Is just something I was always curious about, what is the use of the “PASS” keyword, if in GDscript you can return void by simply calling return and nothing else? Is “PASS” related to threading or something like that?

if im not mistaken pass simply means you ignore and sort of place a “block” of code that does nothing… you can use pass when writing a script with lots and lots of ifs and simply not wanting to implement all the ifs yet and you only write the ifs themselves down

rustyStriker | 2017-10-24 17:04

:bust_in_silhouette: Reply From: volzhs

pass does nothing but it prevents error from empty function or any syntax requires indented line.

for example

func my_func1(): # error if no function body

func my_func2(): # no error but just empty function
   pass # does nothing, but can do it later
func my_func3():
   for i in range(10):  # error if no statements for "for" loop
       pass # no error if "pass" syntax is here when no statements
func my_func4():
   pass # does nothing
   var x = 1 # this code executes

func my_func5():
   return # quit function
   var x = 1 # this code does not execute

OOOOooh I see, I always thought it “returned” empty because I always used as the last line of the function. What it actually does is nothing, hahaha.

Thanks!

henriquelalves | 2017-10-24 17:21

pass is useful for breakpoints too.

eons | 2017-10-25 04:01