Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 79 - 2632_CodeMind
P. 79

    •   Iteration: It executes set of statements for a certain number of times till the given condition is true. For
                         example: Loops.
                      On  the basis  of the above three control structures,  programming  has derived  many types  of control
                      statements to suit different needs.

                             LOOPS

                      Loops are fundamental programming constructs that allow you to repeat a set of instructions multiple
                      times. In MakeCode Arcade, loops are especially useful for tasks like animating sprites, creating repeated
                      patterns, or controlling different elements.

                           Benefits

                         Loops let you repeat actions without writing the same code again and again.
                         They make your code shorter and easier to understand.

                         Loops are great for doing things many times, like moving a character.
                         Changing one loop can update lots of parts of your game at once.

                         Loops make your game more fun by adding repeating animations and patterns
                      For example:  You have five plants lined up in your garden, and you want to water all. Instead of watering
                      each plant individually and keeping track of which ones you've already watered, you can think of using a
                      loop:

                      1.  Start Watering: You begin at the first plant and water it.

                      2.  Move to the Next Plant: After watering the first plant, you move to the second plant.
                      3.   Repeat the Process: You continue watering each plant one by one, moving to the next plant after each
                         one.

                      4.  Finish Watering: Once you've watered the last (fifth) plant, you stop.
                      The loop makes sure you water each plant in turn without skipping any or watering the same one twice.
                      You just follow the same action ("Water the plant") repeatedly until all the plants have been watered.

                           Different Types of Loops

                      Loop runs a statement or group of statements multiple times. There are different types of loops. Let us look
                      at them.

                           Repeat n Times Loop

                      The repeat loop executes a block of code a specified number of times. It's useful when you know exactly
                      how many times you want to repeat an action.
                      Let us create a project in MakeCode Arcade that demonstrates the use of repeat block to display numbers
                      from 1 to 10. To do so, follow the given steps:

                      78    Premium Edition-VIII

| 74 75 76 77 78 79 80 81 82 83 84 |