Raspberry Pi 4 Beginners Guide With Projects: A Step by Step Guide to Master Raspberry Pi 4 and Build Amazing Projects by Edward Roger & Edward Roger
Author:Edward, Roger & Edward, Roger [Edward, Roger]
Language: eng
Format: epub
Published: 2020-08-17T16:00:00+00:00
Variables and Conditionals
Variables : A variable is, as the name suggests, a value that can vary. It also means change over time and under control of the program. A variable has two main properties; its name , and the value it stores .
Although the value is not necessarily a number, it's either in numbers, text, true-or-false, or empty (null) value. Variables are potent tools. For example, there are quite several things to track in a game, such as the health of a character, the speed of moving objects, the level currently being played, and the score. All of these are known as variables.
To start a variable, you need to save your existing File first; click the File menu and save your current program by clicking on the Save Project . Next, click File and then New ; to start a new, blank project. Click on the Data category in the blocks palette, then the 'Make a Variable' button.
Type loops as the variable name then click the OK button to make a series of blocks appear in the blocks palette. Click and drag the set loops to 0 blocks to the scripts area.
This tells your program to initialize the variable with a value of 0. Next, click on the Looks category of the blocks palette and drag the say Hello! for 2 secs block under your set loops to 0 block .
As you found earlier, I say Hello! Blocks cause the cat sprite to say whatever is written in them. Rather than writing the message in the block yourself, though, you can use a variable instead.
Click back onto the Data category in the blocks palette, then click and drag the rounded loops block – known as a reporter block and found at the top of the list, with a tick-box next to it – over the word 'Hello!' in your say Hello! for 2 secs. This creates a new, combined block: say loops for 2 secs.
Click on the Events category in the blocks palette, then drag the block to place it on top of your sequence of blocks. Click the green flag above the stage area, and you'll see the cat sprite say 0; i.e., the value you gave to the variable loops.
Variables aren't unchanging; Click on the Data category in the blocks palette, then click and drag the change loops by one block to the bottom of your sequence. Next, click on the Control category , then click and drag a repeat ten block and drop it so that it starts directly beneath your set loops to 0 blocks and wraps around the remaining blocks in your sequence.
Click the green flag again ; This time, you'll see the cat count upwards from 0 to 9. This works because your program is now changing, or modifying, the variable itself: every time the loop runs, the program adds one to the value in the 'loops' variable.
You can do more with a variable than modifying it. Click and drag the say loops for 2 secs block to break it out of the repeat ten block and drop it below the repeat ten blocks.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
DIY Microcontroller Projects for Hobbyists by Miguel Angel Garcia-Ruiz Pedro Cesar Santana Mancilla(1237)
Raspberry Pi For Dummies by Sean McManus(748)
Computers for Seniors for Dummies by Nancy C. Muir(619)
Troubleshooting and Maintaining PCs All-in-One For Dummies by Dan Gookin(543)
Windows 10: The Missing Manual by Pogue David(518)
Arduino Uno: A Hands-On Guide for Beginner by Agus Kurniawan(464)
Getting Started with Adafruit FLORA by Becky Stern(459)
Teach Yourself VISUALLY Chromebook by Guy Hart-Davis(432)
Samsung Galaxy S6 for Dummies by Bill Hughes(417)
IMac for Dummies by Chambers Mark L.;(368)
Raspberry Pi: A Step-by-Step Guide For Beginners to Program and Set-Up Top 10 Raspberry Pi Projects + First Steps on Configuration by Cage Jonathan(364)
Raspberry Pi 4: The Ultimate Step-by-Step Guide to Using Raspbian to Create Incredible Projects and Expand Your Programming Skills with the Latest Version of Raspberry Pi by Liam Clark(352)
2020 Ultimate Guide to Raspberry Pi : Tips, Tricks and Hacks by oney Youssef & oney Youssef(347)
iPad For Seniors For Dummies by Jesse Feiler(347)
Software Architecture by Neal Ford(336)
Super Arduino: Step-by-Step Instructions to Build Cool Gadgets by Kenneth Hawthorn(331)
Raspberry Pi: Tips and Tricks to Learn Raspberry Pi Programming by Pratt Logan(316)
Build Your Own Autonomous NERF Blaster by Bryce Bigger(310)
RASPBERRY PI 4 : A Comprehensive Guide to Raspberry Pi 4 Setup, Learning Programming and Developing Innovative Projects by DENTON DUKE(308)
