Tutorial 9: Basic While Loop in GDScript

GDScript While Loop

The GDScript above shows the basic uses of while loop to increment and decrement values. In this example the decrement operator -= is introduced. You can download the source code here.

In this tutorial the first while loop starts with value of count 0 and ends with 4, which is less than the maximum value of 5, but it has looped 5 times.

The second while loop starts with 5 and ends with 0, which loops 6 times. And, the final count value after this while loop is -1.

Output Console

As for your practice, try changing the placement of count += 1 and count -= 1 by putting them above the print() function.

Related Posts:

  • Tutorial 9: Basic While Loop in GDScript GDScript While Loop The GDScript above shows the basic uses of while loop to increment and decrement values. In this example the decrement operator -= is introduced. You can download the source code here. In this tutoria… Read More
  • Tutorial 11: Series 1 Exercise 1 in GDScriptextends Node2D const CURRENT_PRINCIPAL: float = 5678.9 const INTEREST_RATE: float = 0.03 const COMPOUND_PER_YEAR: int = 1 var years_to_grow: int = 50 var target_amount: int = 7000 func _ready(): plot_years(CURRENT_PRINCIPA… Read More
  • Tutorial 10: Diamond Shapes using Loops in GDScriptextends Node2D # Draws a diamond with adjustable size func _ready(): # Try changing 6 with even integers from 4 to 26 diamond_for(6) diamond_while(6) func diamond_for(size: int): tri_for(size) #Upside T… Read More
  • Tutorial 7: Basic Match Statement in GDScript GDScript Match Statement The Godot match statement is the equivalent of switch statement in other programming languages. It's a cleaner way of handling conditional statements. If a match statement can handle my conditions… Read More
  • 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. … Read More

0 comments:

Post a Comment

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