programming techniques

Cards (35)

  • what operator do you use to assign a value to a variable?
    =
  • how are variables made global?
    declared with the keyword global (global userid = 123)
  • are variables declared inside a function/procedure local or global?
    local to the subroutine
  • casting?

    assigning a data type to a variable
  • outputting to screen?
    print(string)
  • taking user input?
    variable=input(prompt)
  • what are the two types of iteration?
    condition controlled and count controlled
  • what is a count controlled loop?
    loops based on a predetermined value
  • writing a count controlled loop in ps?
    FOR i=0 TO value, print(whatever), next i, end for
  • what is a condition controlled loop?
    loops until a set condition is met
  • writing a condition controlled loop in ps?
    WHILE condition, whatever the program function is, end while
  • alternative way to write condition controlled loops?
    DO UNTIL function, e.g DO, function of program, UNTIL condition
  • different condition types?
    ==, !=, < >, <= >=
  • when can multiple conditions be included?

    when boolean operators are used
  • arithmetic operators?
    +, -, *, /, MOD, DIV, ^
  • what does MOD and DIV do?
    MOD = modulus, DIV = quotient
  • how do we use more specific mathematical operators?
    by using Math. then your specific function
  • what are the different type of selection functions?
    IF statements and Switch/Case
  • switch/case syntax?
    SWITCH variable, CASE case variable, function, DEFAULT: end switch
  • what does DEFAULT do in switch case?
    it specifies the code to run if no case matches
  • returning the length of a string?

    intLength = stringname.length
  • getting a substring?
    partial = stringname.substring(startPosition, numberOfChars)
  • how to get specific characters in a string?
    addressing individual characters like they are in an array, e.g char3 = stringname[2]
  • what is a subroutine?

    a function or procedure
  • what is the difference between a function and a procedure?
    function returns a value, procedure doesn't
  • defining a subroutine?

    declaring them in code, e.g FUNCTION hello(data), PROCEDURE hello(data)
  • calling subroutines?
    calling the subroutine name and the value to be put into the subroutine
  • what are parameters?
    input values passed into a subroutine, variables within the subroutine brackers
  • how are arrays declared?

    with the keyword array
  • how many dimensions of an array can you have?

    as many as you can make
  • what functions are used when reading a file with file handling?
    openRead and readLine
  • file handling (reading) syntax?
    myFile = openRead("sample.txt"), x = myFile.readLine(), myFile.close
  • what is used to determine the end of the file?
    endOfFile()
  • what functions are used when writing to files?
    openWrite and writeLine
  • file handling (writing) syntax?
    myFile = openWrite("sample.txt"), myFile.writeLine("Hello"), myFile.close()