Contents Coding and Logic 4 Following Instructions 6 Make Better Instructions 8 What Do If and Else Do 10 All About Loops 12 Words and Logic 14 Boolean Logic 16 Switch Statements 18 More About Loops 20 Call the Operators 22 A Logical Order 24 Logical Decisions 26 Can You Pass the Test 28 Glossary 30 For More Information 31 Index 32
Coding and Logic True Logic is reasoning If someone is using logic in everyday life they are explaining something by following a set of rules Guessing is not using logic Everything that a computer does involves logic A computer cannot guess or be random At its most basic level a computer can only test to see if something is true or false False TruE or False Computers use a number system known as binary The binary number system uses two numbers 0 and 1 Computers only really understand two things their electrical supply being off or on Coders can use these two states to get the computer to test for True or False Yes or No or On or Off Coding tips When coders program computers the computer language they use changes the commands into binary Coders don’t have to know binary but it is helpful to understand the logic behind the two states off or on There’s a joke that says Binary is as easy as 1 10 11 Read the next page and see if you can decode the joke 4
Getting BInary Binary is actually simple to learn Look at the chart below If any numbers have a 1 under them you add those numbers together Here there is 1 under 4 and 1 64 32 16 8 4 2 1 0 0 0 0 1 0 1 4 plus 1 is 5 So 5 in binary is written 0 0 0 0 1 0 1 Can you work out what these binary numbers are using this shorter chart a 2 1 b 2 1 c 2 1 0 1 1 0 1 1 Answers are on page 32 GET Programming How does a computer use True or False to work out logical solutions Coders get the computer to ask a question The answer to that question can only be True or False You have some hens and you want to put their eggs into boxes Each egg box holds six eggs If you have more than six eggs you need a second egg box Question Have I got more than six eggs Answer I have seven eggs True get another box I have three eggs False don’t get another box Can you think of some questions you could ask that would only need True or False answers 5