Topics Covered So Far

Preview:

DESCRIPTION

Topics Covered So Far. Variables. int real boolean char const string. Simple formatting. put “this”:10, “is”:10 , “that”:10 -allots 10 character spaces for each element in quotation marks, whether they are strings or numbers put number1:10:2, number2:10:5 - PowerPoint PPT Presentation

Citation preview

Topics Covered So Far

Variables

• int

• real

• boolean

• char

• const

• string

Simple formatting

put “this”:10, “is”:10 , “that”:10

-allots 10 character spaces for each element in quotation marks, whether they are strings or numbers

put number1:10:2, number2:10:5

-allots 10 character spaces to each number and sets number1 to 2 decimal places and number 2 to 5 decimal places

Repetition

• Counted loops versus conditional loops

• Variables declared within a loop only exist while the loop is executing

• Counted (for) loops are more compact and have an automatic variable declared

Counted loops

for count : 1 .. 300put “This will print “, count, “ times.”

end for

var number : int

loop put "Please enter a number." get number exit when number = 10end loop

put "You just entered number 10."

Conditional loops

if - elsif Structure

if length (word) < 4 then put "This word is less than 4 letters long" elsif length (word) < 8 then put "This word is less than 8 letters long" else put "You must be really really super smart!" put " Oh my, to know such a BIG word!" end if

Pre-Built functions

if length (choice) > 4 then

var letter : char

if ord(letter) > 10 and ord(letter) < 100put “what kind of letter is that?”

end if

X := Rand.Int (1, 10)

randint (variable, 1, 10)

Combining Conditions

exit when choice = "No" or choice = "no" or choice = "NO"

if x > 4 and x < 8 thenblah blah

elsif x >8 and x < 100 or x < 0blue blue blue

elsif x = 8Blum blum blum

elseput “what’s left over?”

end if

Concatenation

string1 := character + string1(2..length(string1))

var word2 : stringvar word3: string

word3 := string1 + word2

ASCII

ASCII

(American Standard Code for Information Interchange)

Go To www.asciitable.com

ord (word (count)) will return an ASCII integer value for a char

i.e., word := “hello” ord (word(5)) = 111 this would evaluate as true because

the character “o” has an ASCII value of 111

Go To www.asciitable.com

get skip

Collects end of line markers before getting characters

locate (10,20)

put "Right Now"

delay (1000)

setscreen ("screen")

var row, column, colr : int

loop

randint ( row, 1, maxrow - 1)

randint ( column, 1, maxcol)

randint (colr, 0, maxcolor)

if row = 10 then row := 11 end if

color (colr)

locate (row, column )

put "*" .. % Use dot-dot to avoid clearing end of line

end loop

% locate% Syntax locate ( row, column : int )% % Description The locate procedure is used to move the cursor % so that the next output from put will be at the % given row and column. Row 1 is the top of the screen % and column 1 is the left side of the screen.%

% color % % Syntax color (Color : int)% % Description The color procedure is used to change the currently % active color. This is the color of characters that are % to be put on the screen. The alternate spelling is colour.

setscreen % % setscreen ("graphics:300;100")% % This program outputs the square roots for the first 200 numbers. % The user can inspect all the output and print the values after % the program has finished execution% % setscreen ("text")% for value : 1 .. 200% put value : 3, " ", sqrt (value)% end for% % This program creates a window without a button bar at the top that % is sized to fit the screen. It then draws an "X" in red in the window.% % setscreen ("graphics:max;max,nobuttonbar")% drawline (0, 0, maxx, maxy, red)% drawline (maxx, 0, 0, maxy, red)

Turing Documentation can be found at

http://compsci.ca/holtsoft/doc/