From Test-Scratch-Wiki

The correct title of this article is () < (). The change of name is due to technical restrictions.
() < ()
() < ()
类别 运算类积木
形狀 菱形积木

The () < () 积木 is an 运算类积木 and a 菱形积木. The 积木 checks if the first value is less than the second value. If it is less, the block returns true; if not, it returns false.

This block works with letters too, as well as numbers. In Scratch, letters at the top of the alphabet (e.g. a, b, c) are worth less than letters at the end (e.g. x, y, z). In Scratch 1.3 and previous versions, it only accepted numbers.


Some common uses for the () < () block are below:

  • If a group must be arranged in size, this block can easily do the job by iterating through a list and checking if each value is less than the rest until placement is detected. For example, if a list is supposed to be sorted from greatest to least, the following script can accomplish this:
變數 [i v] 設為 [1] // start at the front
重複 (清單 [numbers v] 的項目數 :: list) 次 
  變數 [i2 v] 設為 [1]
  重複直到 <<(清單第 (i) 項項目\( [numbers v] \) :: list) < (清單第 (i2) 項項目\( [numbers v] \) :: list)> 或 <(i2) > (清單 [numbers v] 的項目數 :: list)>> 
    變數 [i2 v] 改變 (1)
  添加 (清單第 (i) 項項目\( [numbers v] \) :: list) 為第 ((i2) + (1)) 項\( [numbers v] \)
  如果 <(i2) < ((i) + (1))> 那麼 
    刪除第 ((i) + (1)) 項 \( [numbers v] \)
    刪除第 (i) 項 \( [numbers v] \)
  變數 [i v] 改變 (1)
  • Arranging a set of numbers/letters
如果 <<(score) < (清單第 (1 v) 項項目\( [Top Scores v] \) :: list)> 且 <(score) > (清單第 (2 v) 項項目\( [Top Scores v] \) :: list)>> 那麼 
  添加 (score) 為第 (2 v) 項\( [list v] \)
  • Evaluating numbers/letters
變數 [i v] 設為 [1]
刪除第 [全部 v] 項 \( [evaluation v] \)
重複 (清單 [scores v] 的項目數 :: list) 次 
  如果 <(清單第 (i) 項項目\( [scores v] \) :: list) < (5)> 那麼 
    添加 [okay] 為第 (i) 項\( [evaluation v] \) // tells how the score is
    如果 <(清單第 (i) 項項目\( [scores v] \) :: list) < (10)> 那麼 
      添加 [good] 為第 (i) 項\( [evaluation v] \)
      添加 [great!] 為第 (i) 項\( [evaluation v] \)
  end // if the score is lower than 5
  變數 [i v] 改變 (1)
  • Comparing different 变量s (e.g. comparing two characters' health in a game)
如果 <(1 Health) < (2 Health)> 那麼 
  說出 [Player 2 wins]

  說出 [Player 1 wins]
  • Asking for an opinion on a scale of 1 to 10
變數 [confirmed v] 設為 [0] // stores yes or no is the answer is complete and acceptable
重複直到 <(confirmed) = [1]> 
  詢問 [How good are my cookies?] 並等待
  如果 <<(詢問的答案) < (1)> 或 <(詢問的答案) > (10)>> 那麼 
    說出 [The response must be from 1 through 10] (2) 秒
    變數 [confirmed v] 設為 [1]


Main article: List of Block Workarounds

The block can be replicated with the following code:

<<<(a) > (b)> 或 <(a) = (b)>> 不成立>

Less than or equal to

Sometimes it is necessary to know if a value is less than or equal to another value, but there is no block to do so. However, it can be worked around in two ways:

<<(a) > (b)> 不成立>

<<(a) < (b)> 或 <(a) = (b)>>

The first workaround is more efficient.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.