Algorithmic structures
 11.5.3.6 use various algorithmic structures in script language Algorithmic structures  An algorithm is a sequence of actions to achieve a result in a certain number of steps. When you write lines of code, there are three ways you can control the order these lines will be executed by the computer: Sequencing - This means that the computer will run your code in order, one line at a time from the top to the bottom of your program. It will start at line 1, then execute line 2 then line 3 and so on till it reaches the last line of your program. Example,   ```firstname = INPUT ("What is your firstname?") lastname = INPUT ("What is your lastname?") PRINT ("Hello " + firstname + " " + lastname + "!")``` Selection - Sometimes you only want some lines of code to be run only if a condition is met, otherwise you want the computer to ignore these lines and jump over them. This is achieved using IF statements. e.g. If a condition is met then lines 4, 5, 6 are executed otherwise the computer jumps to line 7 without even looking at line 4,5 and 6. Example, ```IF goalsIn == goalsOut:      PRINT "It's a draw" ELSE IF goalsIn > goalsOut:      PRINT "Player 1 wins!" ELSE:      PRINT "Player 2 wins!"``` Iteration - Sometimes you want the computer to execute the same lines of code several times. This is done using a loop. There are three types of loops: For loops, while loops and repeat until loops. That’s handy as it enables you not to have to copy the same lines of code many times. Example, ```WHILE (timer > 0):      PRINT "Carry on playing..."      timer = timer - 1``` OR ```PRINT ("---- 7 Times Table ----") FOR number FROM 1 TO 10:      PRINT 7 * number``` Questions: Give definition for term "algorithm". Explain what does "loop" mean. Describe differences between linear algorithm and algorithm which has a condition. Explain why a programmer should use iteration in his code. Exercises: Ex. 1 Ex. 2 Exam questions: .u-star-rating-13 { list-style:none; margin:0px; padding:0px; width:65px; height:13px; position:relative; background: url('/.s/t/2001/rating13.png') top left repeat-x } .u-star-rating-13 li{ padding:0px; margin:0px; float:left } .u-star-rating-13 li a { display:block;width:13px;height: 13px;line-height:13px;text-decoration:none;text-indent:-9000px;z-index:20;position:absolute;padding: 0px;overflow:hidden } .u-star-rating-13 li a:hover { background: url('/.s/t/2001/rating13.png') left center;z-index:2;left:0px;border:none } .u-star-rating-13 a.u-one-star { left:0px } .u-star-rating-13 a.u-one-star:hover { width:13px } .u-star-rating-13 a.u-two-stars { left:13px } .u-star-rating-13 a.u-two-stars:hover { width:26px } .u-star-rating-13 a.u-three-stars { left:26px } .u-star-rating-13 a.u-three-stars:hover { width:39px } .u-star-rating-13 a.u-four-stars { left:39px } .u-star-rating-13 a.u-four-stars:hover { width:52px } .u-star-rating-13 a.u-five-stars { left:52px } .u-star-rating-13 a.u-five-stars:hover { width:65px } .u-star-rating-13 li.u-current-rating { top:0 !important; left:0 !important;margin:0 !important;padding:0 !important;outline:none;background: url('/.s/t/2001/rating13.png') left bottom;position: absolute;height:13px !important;line-height:13px !important;display:block;text-indent:-9000px;z-index:1 } Категория: Programming languages | Добавил: bzfar77 (09.02.2021) Просмотров: 324 | | Рейтинг: 0.0/0
 Всего комментариев: 0