Difference between revisions of "KTurtle/C3/Control-Execution/English"
| (12 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | Title of the tutorial: Control-Execution | ||
| + | |||
| + | Author: Madhuri Ganapathi | ||
| + | |||
| + | Keywords: control execution, variables, boolean, while loop, for loop, Video tutorial. | ||
| + | |||
| + | |||
{|border =1 | {|border =1 | ||
!Visual Cue | !Visual Cue | ||
| Line 5: | Line 12: | ||
||Slide Number 1 | ||Slide Number 1 | ||
|| | || | ||
| − | |||
| − | |||
Hello Everybody. | Hello Everybody. | ||
| Line 13: | Line 18: | ||
||Slide Number 2 | ||Slide Number 2 | ||
| − | Learning Objectives | + | '''Learning Objectives''' |
||In this tutorial, we will learn | ||In this tutorial, we will learn | ||
| − | |||
| − | '''' | + | * ''''while'''' loop and |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | * 'for' loop | + | * ''''for'''' loop |
|- | |- | ||
|| Slide Number 3 | || Slide Number 3 | ||
| Line 53: | Line 51: | ||
||Let's open a new '''KTurtle''' Application. | ||Let's open a new '''KTurtle''' Application. | ||
| − | Click on '''Dash home | + | Click on '''Dash home'''. |
In the Search bar, type KTurtle. | In the Search bar, type KTurtle. | ||
| Line 61: | Line 59: | ||
|- | |- | ||
|| | || | ||
| − | ||Let me first explain about what is control execution | + | ||Let me first explain about what is control execution? |
|- | |- | ||
||Slide Number 5 | ||Slide Number 5 | ||
| − | Control execution | + | '''Control execution''' |
||Control execution is controlling the flow of a program. | ||Control execution is controlling the flow of a program. | ||
| Line 72: | Line 70: | ||
||Slide Number 6 | ||Slide Number 6 | ||
| − | Loop | + | '''Loop''' |
| − | ||Loop is a block of code is executed repeatedly | + | ||Loop is a block of code is executed repeatedly till a certain condition is satisfied. |
Eg. '''“while”''' loop and '''“for”''' loop | Eg. '''“while”''' loop and '''“for”''' loop | ||
|- | |- | ||
| Line 81: | Line 79: | ||
||Slide Number 7 | ||Slide Number 7 | ||
| − | “while” loop | + | '''“while” loop''' |
||In the '''“while'''” loop, the code inside the loop repeats till '''boolean''' evaluates to 'false'. | ||In the '''“while'''” loop, the code inside the loop repeats till '''boolean''' evaluates to 'false'. | ||
|- | |- | ||
||Slide Number 8 | ||Slide Number 8 | ||
| − | Syntax of “while” loop | + | '''Syntax of “while” loop''' |
||Let me explain the structure of '''“while”''' loop. | ||Let me explain the structure of '''“while”''' loop. | ||
| − | '''while loop condition { | + | |
| − | do something | + | '''while loop condition''' { |
| − | + | ||
| + | '''do something ''' | ||
| + | |||
| + | '''with loop increment variable | ||
}''' | }''' | ||
|- | |- | ||
|| | || | ||
| − | || | + | ||I already have the code in a text editor. |
| − | + | ||
| − | I already have the code in a text editor. | + | |
|- | |- | ||
| + | |||
||'''#program to print a series of multiples 3 upto 30''' | ||'''#program to print a series of multiples 3 upto 30''' | ||
'''reset''' | '''reset''' | ||
| + | |||
'''$x=0''' | '''$x=0''' | ||
| + | |||
'''message"In while loop, code inside the loop repeats till boolean evaluates false"''' | '''message"In while loop, code inside the loop repeats till boolean evaluates false"''' | ||
| + | |||
'''while $x<30''' { | '''while $x<30''' { | ||
| + | |||
'''$x=$x+3''' | '''$x=$x+3''' | ||
| + | |||
'''fontsize 15''' | '''fontsize 15''' | ||
| + | |||
'''forward 20''' | '''forward 20''' | ||
| + | |||
'''print $x''' | '''print $x''' | ||
} | } | ||
| Line 113: | Line 120: | ||
Please pause the tutorial here and type the program into your '''KTurtle''' editor. | Please pause the tutorial here and type the program into your '''KTurtle''' editor. | ||
| − | + | ||
| + | Resume the turtorial after typing the program | ||
|- | |- | ||
|| | || | ||
| Line 119: | Line 127: | ||
|- | |- | ||
|| | || | ||
| − | ||Let me explain the | + | ||Let me explain the program. |
|- | |- | ||
||Highlight # | ||Highlight # | ||
| Line 128: | Line 136: | ||
||'''reset''' command sets '''“Turtle'''” to its '''default''' position. | ||'''reset''' command sets '''“Turtle'''” to its '''default''' position. | ||
|- | |- | ||
| − | ||Highlight $x | + | ||Highlight '''$x''' |
||'''$x=0''' initialises the value of variable x to zero. | ||'''$x=0''' initialises the value of variable x to zero. | ||
|- | |- | ||
||Highlight '''message" "''' | ||Highlight '''message" "''' | ||
| − | ||Message in a program is given within double quotes after the keyword message " " | + | ||Message in a program is given within double quotes after the '''keyword''' '''message " "''' |
| − | '''“message”''' command takes “string” as input. | + | |
| + | '''“message”''' command takes '''“string”''' as input. | ||
| + | |||
It shows a pop-up dialog box containing text from the string. | It shows a pop-up dialog box containing text from the string. | ||
|- | |- | ||
| Line 144: | Line 154: | ||
||Highlight '''fontsize 15''' | ||Highlight '''fontsize 15''' | ||
||'''fontsize 15 ''' sets the font size used by '''print''' command. | ||'''fontsize 15 ''' sets the font size used by '''print''' command. | ||
| + | |||
Fontsize takes number as input, set in pixels. | Fontsize takes number as input, set in pixels. | ||
|- | |- | ||
| Line 158: | Line 169: | ||
Let me click OK. | Let me click OK. | ||
|- | |- | ||
| − | ||Run the program | + | ||'''Run the program''' |
||Multiples of 3 from 3 to 30 are displayed on the canvas. | ||Multiples of 3 from 3 to 30 are displayed on the canvas. | ||
'''“Turtle”''' moves 20 steps forward on the canvas. | '''“Turtle”''' moves 20 steps forward on the canvas. | ||
|- | |- | ||
|| | || | ||
| − | || | + | ||Let's next work with '''“for”''' loop |
| − | Let's next work with '''“for”''' loop | + | |
|- | |- | ||
||Slide Number 9 | ||Slide Number 9 | ||
| − | "for" loop | + | |
| + | '''"for" loop''' | ||
||“for” loop is a counting loop. | ||“for” loop is a counting loop. | ||
| − | Every time the code inside “for” loop is executed, | + | Every time the code inside '''“for”''' loop is executed, |
variable value is incremented, till it reaches the end value. | variable value is incremented, till it reaches the end value. | ||
| Line 176: | Line 187: | ||
||Slide Number 10 | ||Slide Number 10 | ||
| − | Syntax of “for” loop | + | '''Syntax of “for” loop''' |
| − | ||Let me explain the structure of “for” loop. | + | ||Let me explain the structure of '''“for”''' loop. |
'''for variable = start number to end number { Statement}''' | '''for variable = start number to end number { Statement}''' | ||
|- | |- | ||
| − | ||Clear the editor and canvas | + | ||'''Clear the editor and canvas''' |
||Let me clear the current program. | ||Let me clear the current program. | ||
| − | Let me type clear command and run to clean the canvas. | + | Let me type '''clear''' command and run to clean the canvas. |
|- | |- | ||
||'''#program print to sum of first 15 natural numbers | ||'''#program print to sum of first 15 natural numbers | ||
| + | |||
''reset''' | ''reset''' | ||
| + | |||
'''$r=0''' | '''$r=0''' | ||
| + | |||
'''for $x= 1 to 15'''{ | '''for $x= 1 to 15'''{ | ||
| + | |||
'''$r=$x*($x+1)/2''' | '''$r=$x*($x+1)/2''' | ||
| + | |||
'''fontsize 18''' | '''fontsize 18''' | ||
| + | |||
'''print $r''' | '''print $r''' | ||
| + | |||
'''forward 15''' | '''forward 15''' | ||
} | } | ||
| − | '''go 10,250'' | + | |
| + | '''go 10,250''' | ||
| + | |||
'''wait 2''' | '''wait 2''' | ||
| + | |||
'''print "Sum of first 15 natural numbers ="+$r''' | '''print "Sum of first 15 natural numbers ="+$r''' | ||
| − | ||Let me copy the program and paste it into KTurtle editor | + | ||Let me copy the program from text editor and paste it into KTurtle's editor |
Please pause the tutorial here and type the program into your KTurtle editor. | Please pause the tutorial here and type the program into your KTurtle editor. | ||
| − | + | Resume the turtorial after typing the program. | |
|- | |- | ||
|| | || | ||
| Line 209: | Line 230: | ||
|- | |- | ||
|| | || | ||
| − | ||Let me explain the | + | ||Let me explain the program. |
|- | |- | ||
||Highlight # | ||Highlight # | ||
| Line 215: | Line 236: | ||
|- | |- | ||
||Highlight '''reset''' | ||Highlight '''reset''' | ||
| − | ||'''reset''' command sets '''“Turtle”''' to '''default''' position. | + | ||'''reset''' command sets '''“Turtle”''' to its '''default''' position. |
|- | |- | ||
||Highlight '''$r=0''' | ||Highlight '''$r=0''' | ||
| Line 230: | Line 251: | ||
|- | |- | ||
||Highlight '''print $r''' | ||Highlight '''print $r''' | ||
| − | ||'''print $r''' displays the variable r. | + | ||'''print $r''' displays the value of variable r on the canvas. |
|- | |- | ||
| − | ||Highlight forward 15 | + | ||Highlight '''forward 15''' |
| − | ||forward 15 | + | ||'''forward 15''' commands '''Turtle''' to move 15 steps foward on the canvas. |
|- | |- | ||
||Highlight '''go 10,250''' | ||Highlight '''go 10,250''' | ||
| Line 240: | Line 261: | ||
||Highlight '''wait 2''' | ||Highlight '''wait 2''' | ||
||'''“Turtle”''' displays all print commands without any time gap. | ||'''“Turtle”''' displays all print commands without any time gap. | ||
| − | “Wait 2” command makes Turtle to | + | “Wait 2” command makes Turtle to wait for 2 seconds before executing next command. |
|- | |- | ||
||'''print "Sum of first 15 natural numbers ="+$r''' | ||'''print "Sum of first 15 natural numbers ="+$r''' | ||
| Line 246: | Line 267: | ||
|- | |- | ||
||'''Run the program''' | ||'''Run the program''' | ||
| − | ||Let me click the '''“ Run”''' button to run the program. | + | ||Let me click the on '''“ Run”''' button to run the program. |
| − | A series of sum of first 15 numbers and sum of first 15 natural numbers is displayed on the canvas. | + | |
| − | '''Turtle''' moves 15 steps forward. | + | A series of sum of first 15 natural numbers and sum of first 15 natural numbers is displayed on the canvas. |
| + | |||
| + | '''Turtle''' moves 15 steps forward on the canvas. | ||
|- | |- | ||
|| | || | ||
||With this we come to end of this tutorial. | ||With this we come to end of this tutorial. | ||
|- | |- | ||
| − | Slide Number 11 | + | ||Slide Number 11 |
'''Summary''' | '''Summary''' | ||
||Let us summarize. | ||Let us summarize. | ||
In this tutorial we have learnt to use, | In this tutorial we have learnt to use, | ||
| + | |||
* '''“while”''' loop and | * '''“while”''' loop and | ||
| Line 263: | Line 287: | ||
|- | |- | ||
||Slide Number 12 | ||Slide Number 12 | ||
| + | |||
'''Assignment''' | '''Assignment''' | ||
||As an assignment I would like you to write programs to evaluate | ||As an assignment I would like you to write programs to evaluate | ||
| Line 270: | Line 295: | ||
* Multiplication table of a number using “for” loop | * Multiplication table of a number using “for” loop | ||
|- | |- | ||
| − | ||Slide number | + | ||Slide number 13 |
||'''Acknowledgement''' | ||'''Acknowledgement''' | ||
| + | |||
Watch the video available at this URL | Watch the video available at this URL | ||
| Line 280: | Line 306: | ||
If you do not have good bandwidth, you can download and watch it | If you do not have good bandwidth, you can download and watch it | ||
|- | |- | ||
| − | ||Slide Number | + | ||Slide Number 14 |
||The Spoken Tutorial Project Team : | ||The Spoken Tutorial Project Team : | ||
| Line 292: | Line 318: | ||
contact@spoken-tutorial.org | contact@spoken-tutorial.org | ||
|- | |- | ||
| − | ||Slide number | + | ||Slide number 15 |
||Spoken Tutorial Project is a part of the Talk to a Teacher project | ||Spoken Tutorial Project is a part of the Talk to a Teacher project | ||
| Line 302: | Line 328: | ||
This is Madhuri Ganpathi from IIT Bombay signing off | This is Madhuri Ganpathi from IIT Bombay signing off | ||
Thank you for joining | Thank you for joining | ||
| + | |- | ||
Latest revision as of 15:50, 18 December 2013
Title of the tutorial: Control-Execution
Author: Madhuri Ganapathi
Keywords: control execution, variables, boolean, while loop, for loop, Video tutorial.
| Visual Cue | Narration |
|---|---|
| Slide Number 1 |
Hello Everybody. Welcome to this tutorial on Control Execution in KTurtle |
| Slide Number 2
Learning Objectives |
In this tutorial, we will learn
|
| Slide Number 3
System Requirement |
To record this tutorial I am using,
Ubuntu Linux OS Version 12.04 KTurtle version 0.8.1 beta. |
| Slide Number 4
Pre-requisites |
We assume that you have basic working knowledge of Kturtle.
If not, for relevant tutorials, please visit our website. http://spoken-tutorial.org |
| Switch to KTurtle Application
Dash home >>Search bar appears>> In the Search bar type KTurtle |
Let's open a new KTurtle Application.
Click on Dash home. In the Search bar, type KTurtle. Click on the option. KTurtle Application opens. |
| Let me first explain about what is control execution? | |
| Slide Number 5
Control execution |
Control execution is controlling the flow of a program.
Different conditions are used to control program execution. |
| Slide Number 6
Loop |
Loop is a block of code is executed repeatedly till a certain condition is satisfied.
Eg. “while” loop and “for” loop |
| Let's begin the tutorial with “while” loop | |
| Slide Number 7
“while” loop |
In the “while” loop, the code inside the loop repeats till boolean evaluates to 'false'. |
| Slide Number 8
Syntax of “while” loop |
Let me explain the structure of “while” loop.
while loop condition { do something with loop increment variable } |
| I already have the code in a text editor. | |
| #program to print a series of multiples 3 upto 30
reset $x=0 message"In while loop, code inside the loop repeats till boolean evaluates false" while $x<30 { $x=$x+3 fontsize 15 forward 20 print $x } |
Let me copy the program from text editor and paste it into KTurtle editor
Resume the turtorial after typing the program |
| Let me zoom into the program text it may possibly be a little blurred. | |
| Let me explain the program. | |
| Highlight # | # sign comments a line written after it.
It means, this line will not be executed while running the program. |
| Highlight reset | reset command sets “Turtle” to its default position. |
| Highlight $x | $x=0 initialises the value of variable x to zero. |
| Highlight message" " | Message in a program is given within double quotes after the keyword message " "
“message” command takes “string” as input. It shows a pop-up dialog box containing text from the string. |
| Highlight while $x<30 | while $x<30 checks the “while” condition. |
| Highlight $x=$x+3 | $x=$x+3 increments the value of variable $x by 3 |
| Highlight fontsize 15 | fontsize 15 sets the font size used by print command.
Fontsize takes number as input, set in pixels. |
| Highlight forward 20 | forward 20 commands “Turtle” to move 20 steps forward on the canvas. |
| Highlight print $x | print $x displays the value of variable x on the canvas. |
| Run the program | Let me click on the “Run” button to run the program.
A message dialog box pops up. Let me click OK. |
| Run the program | Multiples of 3 from 3 to 30 are displayed on the canvas.
“Turtle” moves 20 steps forward on the canvas. |
| Let's next work with “for” loop | |
| Slide Number 9
"for" loop |
“for” loop is a counting loop.
Every time the code inside “for” loop is executed, variable value is incremented, till it reaches the end value. |
| Slide Number 10
Syntax of “for” loop |
Let me explain the structure of “for” loop.
for variable = start number to end number { Statement} |
| Clear the editor and canvas | Let me clear the current program.
Let me type clear command and run to clean the canvas. |
| #program print to sum of first 15 natural numbers
reset' $r=0 for $x= 1 to 15{ $r=$x*($x+1)/2 fontsize 18 print $r forward 15 } go 10,250 wait 2 print "Sum of first 15 natural numbers ="+$r |
Let me copy the program from text editor and paste it into KTurtle's editor
Resume the turtorial after typing the program. |
| Let me zoom into the program text it may possibly be a little blurred. | |
| Let me explain the program. | |
| Highlight # | # sign comments a line written after it. |
| Highlight reset | reset command sets “Turtle” to its default position. |
| Highlight $r=0 | $r=0 initialises the value of variable r to zero. |
| Highlight for $x= 1 to 15 | for $x= 1 to 15 checks “for” condition from 1 to 15. |
| Highlight $r=$x*($x+1)/2 | $r=$x*($x+1)/2 calculates the value of variable r. |
| Highlight fontsize 18 | fontsize 18 sets the font size used by print command. |
| Highlight print $r | print $r displays the value of variable r on the canvas. |
| Highlight forward 15 | forward 15 commands Turtle to move 15 steps foward on the canvas. |
| Highlight go 10,250 | go 10,250 commands Turtle to go 10 pixels from left of canvas and 250 pixels from top of canvas. |
| Highlight wait 2 | “Turtle” displays all print commands without any time gap.
“Wait 2” command makes Turtle to wait for 2 seconds before executing next command. |
| print "Sum of first 15 natural numbers ="+$r | “print” command displays the “string” within double quotes and also displays variable $r. |
| Run the program | Let me click the on “ Run” button to run the program.
A series of sum of first 15 natural numbers and sum of first 15 natural numbers is displayed on the canvas. Turtle moves 15 steps forward on the canvas. |
| With this we come to end of this tutorial. | |
| Slide Number 11
Summary |
Let us summarize.
In this tutorial we have learnt to use,
|
| Slide Number 12
Assignment |
As an assignment I would like you to write programs to evaluate
|
| Slide number 13 | Acknowledgement
Watch the video available at this URL http://spoken-tutorial.org/What is a Spoken Tutorial It summarises the Spoken Tutorial project If you do not have good bandwidth, you can download and watch it |
| Slide Number 14 | The Spoken Tutorial Project Team :
Conducts workshops using spoken tutorials Gives certificates to those who pass an online test For more details, please write to contact@spoken-tutorial.org |
| Slide number 15 | Spoken Tutorial Project is a part of the Talk to a Teacher project
It is supported by the National Mission on Education through ICT, MHRD, Government of India More information on this Mission is available at this link http://spoken-tutorial.org/NMEICT-Intro ] This is Madhuri Ganpathi from IIT Bombay signing off Thank you for joining |