mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-03 05:48:42 +03:00
Improved documentation for GDScript in keyword (#5883)
* Improve 'in' operator description
* Apply syntax suggestions from code review
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
(cherry picked from commit 22f820a036)
This commit is contained in:
committed by
Rémi Verschelde
parent
9d7de8e55d
commit
51b9979a69
@@ -265,7 +265,12 @@ The following is the list of supported operators and their precedence.
|
||||
+------------------------------------------------------------------------+-----------------------------------------+
|
||||
| ``<`` ``>`` ``==`` ``!=`` ``>=`` ``<=`` | Comparisons |
|
||||
+------------------------------------------------------------------------+-----------------------------------------+
|
||||
| ``in`` | Content test |
|
||||
| ``in`` | When used with the ``if`` keyword it |
|
||||
| | checks if a value is within a string, |
|
||||
| | list, range, dictionary, or node. When |
|
||||
| | used with the ``for`` keyword it is used|
|
||||
| | to iterate though the contents of a |
|
||||
| | string, list, range, dictionary or node.|
|
||||
+------------------------------------------------------------------------+-----------------------------------------+
|
||||
| ``!`` ``not`` | Boolean NOT |
|
||||
+------------------------------------------------------------------------+-----------------------------------------+
|
||||
@@ -858,6 +863,16 @@ multiple lines to preserve readability::
|
||||
else "orange"
|
||||
print(fruit_alt) # banana
|
||||
|
||||
You may also wish to check if a value is contained within something. You can
|
||||
use an ``if`` statement combined with the ``in`` operator to accomplish this::
|
||||
|
||||
# Check if a letter is in a string.
|
||||
var text = "abc"
|
||||
if 'b' in text: print("The string contains b")
|
||||
|
||||
# Check if a variable is contained within a node.
|
||||
if "varName" in get_parent(): print("varName is defined in parent!")
|
||||
|
||||
while
|
||||
^^^^^
|
||||
|
||||
|
||||
Reference in New Issue
Block a user