Tutorial 8: Basic For Loop in GDScript

GDScript of Basic For Loop

In this example, it shows the basic uses of a for loop statement. One is to increment and the other decrements the value of 'n'. There are other usages but for now let's tackle the common ones. You can download the source code here.

This example builds from the previous tutorials, and includes concepts from the previous lessons. If there are things here that are new to you, then I suggest studying the previous posts in Series 1 Tutorials.

Apart from the for loop examples, this tutorial introduces the use of increment operators like += .

The first for loop starts from 0 and ends with 2 (range(3)), the second does the opposite, which starts from 3 and decrements till it ends with 1 (range(3, 0, -1)), the last one does a similar thing like the first one, but for the sake of implementations let's use (range(0, 3, 1)). Each for loop calls a function prnt() to print the number of loops and 'n' values.

Output Console


As for your practics, try changing the range values and see what happens.

Related Posts:

  • Tutorial 3: Basic Operators in GDScript GDScript Basic Operators In this tutorial, you'll learn how to use the basic operators like addition, subtraction, multiplication and division used in the compound interest formula, as shown above. You can download the so… Read More
  • Tutorial 2: Basic Variables in GDScript GDScript with Specific Variable Types and Scoping The image above shows a GDScript with basic variables declared with specific types, and with proper scoping. You can download the source code here. In this example, we so… Read More
  • Tutorial 4: Basic Functions in GDScript GDScript with Basic Functions Declaring a function in GDScript is not difficult; just like what is shown in the image above. You can declare a function with func someFunctionName(some_variable): , but I prefer declaring i… Read More
  • Tutorial 5: Basic Functions in GDScript Part 2 GDScript for Determining an Even or Odd Number This is the second part of the function tutorial. Please study the previous tutorials before studying this one; it builds from the concepts of the past tutorials 1 to 4. The… Read More
  • Tutorial 6: Basic Conditional Statements in GDScript GDScript of Basic Conditional Statements The basic GDScript conditional statements shown above is pretty much straightforward. It simply uses the if, elif and else statements. You can download the source code here. In th… Read More

0 comments:

Post a Comment

© 2020 by Emman Lijesta, all rights reserved. Powered by Blogger.