KTurtle/C3/Control-Execution/English

From Script | Spoken-Tutorial
Revision as of 17:13, 26 December 2012 by Madhurig (Talk | contribs)

Jump to: navigation, search
Visual Cue Narration
Slide Number 1

Hello everybody.

Hello Everybody.

Welcome to this tutorial on Control Execution in KTurtle

Slide Number 2

Learning Objectives

In this tutorial, we will learn

'while' loop and 'for' loop

Slide Number 2

Learning Objectives

In this tutorial, we will learn
  • 'while' loop and
  • 'for' loop
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. The Search bar appears. 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 untill 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


Please pause the tutorial here and type the program into your KTurtle editor. Please 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 code.
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 and paste it into KTurtle editor


Please pause the tutorial here and type the program into your KTurtle editor. Please resume the turtorial after typing the program.

Contributors and Content Editors

Madhurig