ICT
the blog for ICT
ken013194
暱稱: ホロ
性別: 男
國家: 香港
地區: 葵青區
« June 2026 »
SMTWTFS
123456
78910111213
14151617181920
21222324252627
282930
最新文章
Text File
Arrays
String Procedures
String Functions
String Operation
文章分類
全部 (23)
Programming Language (23)
訪客留言
最近三個月尚無任何留言
每月文章
日誌訂閱
尚未訂閱任何日誌
好友名單
尚無任何好友
網站連結
尚無任何連結
最近訪客
最近沒有訪客
日誌統計
文章總數: 23
留言總數: 0
今日人氣: 0
累積人氣: 48
站內搜尋
RSS 訂閱
RSS Feed
2009 年 9 月 11 日  星期五   晴天


Basic Control Stru 分類: Programming Language

High-level Programming Language (Pascal)

Boolean Expressions

  • implementing selection and repetition structures involves Boolean expressions
  • Boolean expressions may be either simple or compound
  • Boolean data type
    • there are two Boolean constants, true and false
    • Boolean variables may have only these values (either true or false)
    • the type identifier Boolean is used to specify the type of a Boolean variable
    • for example,


     var Found : Boolean;

    which declares that Found is a Boolean variable

    • Boolean values may be displayed with write or writeln statements
    • but values for Boolean variables cannot be read
    • a Boolean variable may be assigned a value with an assignment statement of the form


    Boolean_variable := Boolean_expression

    • for example,


     Female := true;

    which assigns the Boolean constant true to the Boolean variable Femal

  • Boolean expressions can contain a combination of arithmetic, relational and Boolean operators
  • the precedence of operator determines its order of evaluation
  • the table below shows the precedence of operators in Pascal

    Pascal Operator
    (Arithmetic, Relational, Boolean)
    Order of Precedence
    ( ) (parentheses)
    1 highest (performed first)
    - (unary operator) , not
    2
    * , / , div , mod , and
    3
    + , - , or
    4
    = , <> , > , >= , < , <=
    5 lowest (performed last)

     

Simple Boolean Expression

  • describes a relationship between two quantities and it has the form

    <expression_1> <relational operator> <expression_2>

    • where <expression_1> and <expression_2> must be compatible, that is, numeric data must match with numeric data, and alphanumeric data with alphanumeric data which can either be a character or a string
    • the relational operator may be any of the following :

      Mathematical Relational Operator
      Pascal Relational Operator
      Meaning
      =
      =
      equal to
      <>
      not equal to
      >
      >
      greater than
      >=
      greater than or equal to
      <
      <
      less than
      <=
      less than or equal to

      • relational operators can be used with numeric constant, numeric variable, arithmetic expression, character and string
      • within the computer, the characters are ordered in a sequence according to a certain coding scheme
      • a commonly used scheme is the American Standard Code for Information Interchange (ASCII)

         
    • for example, the Boolean expressions in the table below are evaluated assuming the following variables values :

      Score
      PassMark
      49
      50

      Boolean Expression
      Meaning
      Result
      Reason
      5 > 1
      5 is greater than 1
      true
      5 is greater 1 is true
      'A' < 'F'
      character 'A' is less than character 'F'
      true
      the ASCII code of 'A' (65) which is less than the ASCII code of F (70)
      '12345' > '200'
      character '12345' is greater than character '200'
      false
      the ASCII code of the first character of '12345' is not greater than the ASCII code of the first character of '200'
      12345 > 200
      12345 is greater than 200
      true
       
      '4A' > '4'
      character '4A' is greater than character '4'
      true
       
      3*2 > 1+7
      3 times 2 is greater than 1 plus 7
      false
      3 times 2 (i.e. 6) is not greater than 1 plus 7 (i.e. 8)
      Score < PassMark
      Score is less than PassMark
      true
      Score (49) is less than PassMark (50) is true

Compound Boolean Expressions

  • are formed by combining Boolean expressions using the Boolean operators : and, or and not
    • for example, to determine whether an integer is greater than zero but less than 100, we can form a compound Boolean expression as follows :

       (Number > 0) and (Number < 100)

      If the variable Number equals to 99, then the Boolean value of the Boolean expression becomes true

    • Suppose A and B represent two simple Boolean expressions. The following truth table summarize all possible values for A and B and the corresponding values of the compound Boolean expressions.

      A
      B
      A and B
      A or B
      not A
      true
      true
      true
      true
      false
      true
      false
      false
      true
      false
      false
      true
      false
      true
      true
      false
      false
      false
      false
      true

 



Boolean Exp 分類: Programming Language

High-level Programming Language (Pascal)

Boolean Expressions

  • implementing selection and repetition structures involves Boolean expressions
  • Boolean expressions may be either simple or compound
  • ......

    (閱讀全文)



Assignment Stat 分類: Programming Language

High-level Programming Language (Pascal)

Assignment Statements

  • gives a value or computational result to a variable
  • the syntax of an assignment statement is

    <variable> := &......

    (閱讀全文)



Math Functions 分類: Programming Language

High-level Programming Language (Pascal)

Mathematical Functions

  • predefined functions that are used to perform arithmetic operation in Pascal
  • common characteristic of Pascal function


Arithmetic Exp 分類: Programming Language

High-level Programming Language (Pascal)

Arithmetic Expressions in Pascal

  • similar to the mathematical expressions
  • an expression can be a constant, a variable o......

    (閱讀全文)