19
Topics Covered So Far

Topics Covered So Far

  • Upload
    jaimie

  • View
    59

  • Download
    0

Embed Size (px)

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

Page 1: Topics Covered So Far

Topics Covered So Far

Page 2: Topics Covered So Far

Variables

• int

• real

• boolean

• char

• const

• string

Page 3: Topics Covered So Far

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

Page 4: Topics Covered So Far

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

Page 5: Topics Covered So Far

Counted loops

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

end for

Page 6: Topics Covered So Far

var number : int

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

put "You just entered number 10."

Conditional loops

Page 7: Topics Covered So Far
Page 8: Topics Covered So Far

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

Page 9: Topics Covered So Far

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)

Page 10: Topics Covered So Far

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

Page 11: Topics Covered So Far

Concatenation

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

var word2 : stringvar word3: string

word3 := string1 + word2

Page 12: Topics Covered So Far

ASCII

Page 13: Topics Covered So Far

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

Page 14: Topics Covered So Far

get skip

Collects end of line markers before getting characters

Page 15: Topics Covered So Far

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

Page 16: Topics Covered So Far

% 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.%

Page 17: Topics Covered So Far

% 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.

Page 18: Topics Covered So Far

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)

Page 19: Topics Covered So Far

Turing Documentation can be found at

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