Page 92 - Computer Genius Class 07
P. 92

If Else Conditional Statements in Coding

                  “If you score well in exams, Then you will get a PlayStation .”

                  This sentence can be used to understand a key concept in coding—Conditional Statements.
                  Conditional statements help us direct the computer what to do and when to do it. Conditions are the
                  main part of the decision making process for computers.






















                  When a series of decision is required, Nested if–else statements are used. They are collection of if
                  else statements that have been combined and used within one another.

                  Program to Check Odd and Even Number

                  To create an AI Connect program to check if the number is odd or even, create a project. In this

                  project create a Basic Coding activity. Then follow the given steps:
                   Step 1   Go to the Variables category and click on the Create variable... block to create a variable
                            num.


                            Drag and drop set num to block from Variables category. Add int block from conversion
                            category inside this block. Then, add input with prompt block from Input category inside
                            int block.


                   Step 2   Attach if-do block from Logic category. Click on setting button of if-do block and add else
                            block in if-do block to extend it.


                   Step 3   Add equal block inside if-do block. In it add % block on the left side of == and numeric block
                            (with 0 value) on the right side. Add num block on the left side of % block and numeric
                            block (with value 2) on the right side.


                              ere  mathematical conditions is used to chec   or an e en num er using the Arithmetic
                            Operators and Logical Operators blocks. And the condition used here is, when the number
                            divided by 2 gives remainder as 0, then that number is an even number. Else, number is an
                            odd number.)





                      90     Computer Genius-VII
   87   88   89   90   91   92   93   94   95   96   97