(Adds (block) in the incorrect title template)
m (Sorry)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{April Fools}}{{Incorrect Title|() < () (block)}}
 
{{April Fools}}{{Incorrect Title|() < () (block)}}
{{Block
+
{{block
 
|name = () < ()
 
|name = () < ()
|image = File:2.0 ()_is_Less_Than_().png
+
|image = () < ()
 
|category = [[Operators Blocks|Operators]]
 
|category = [[Operators Blocks|Operators]]
 
|type = [[Boolean Block|Boolean]]
 
|type = [[Boolean Block|Boolean]]
|defaults = Blank insert; blank insert
+
|sb = yes
 
}}
 
}}
The '''() < ()''' [[Blocks|block]] is an [[Operators Blocks|Operators block]] and a [[Boolean Block|Boolean block]]. The [[Blocks|block]] checks if the first value is less than the second value. If it is less, the block returns ''true''; if not, it returns ''false''.
+
The '''() < ()''' [[Blocks|block]] is an [[Operators Blocks|Operators block]] and a [[Boolean Block|Boolean block]]. The block reports ''true'' if the first value is less than the second value and ''false'' otherwise.
  
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.
+
This block can compare both numbers and [[string]]s, which are ordered alphabetically. In [[Scratch 1.3]] and previous versions, it only accepted numbers.
  
 
==Example Uses==
 
==Example Uses==
 
Some common uses for the () < () block are below:
 
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:
+
 
 +
* [[Sorting Values|Sorting]]
 +
* Inserting an item in a sorted [[list]]
 +
 
 
<scratchblocks>
 
<scratchblocks>
set [i v] to [1] //start at the front
+
set [i v] to [1]
repeat (length of [numbers v])
+
repeat until <<(i) > (length of [scores v])> or <(item (i) of [scores v]) < (score)>>
set [i2 v] to [1]
+
    change [i v] by (1)
repeat until <<(item (i) of [numbers v]) < (item (i2) of [numbers v])> or <(i2) > (length of [numbers v])
 
change [i2 v] by (1)
 
end
 
insert (item (i) of [numbers v]) at ((i2) + (1)) of [numbers v]
 
if <(i2) < ((i) + (1))> then
 
delete ((i) + (1)) of [numbers v]
 
else
 
delete (i) of [numbers v]
 
end
 
change [i v] by (1)
 
 
end
 
end
 +
insert (score) at (i) of [scores v]
 
</scratchblocks>
 
</scratchblocks>
  
*Arranging a set of numbers/letters
+
* Evaluating numbers or letters
 +
 
 
<scratchblocks>
 
<scratchblocks>
if <<(score) < (item (1 v) of [Top Scores v])> and <(score) > (item (2 v) of [Top Scores v])>> then
+
if <(score) < (5)> then
      
+
    say [Poor job.] for (1) secs
insert (score) at (2 v) of [list v]
+
     stop [this script v]
 
end
 
end
</scratchblocks>
 
 
*Evaluating numbers/letters
 
<scratchblocks>
 
set [i v] to [1]
 
delete [all v] of [evaluation v]
 
repeat (length of [scores v])
 
if <(item (i) of [scores v]) < (5)> then //if the score is lower than 5
 
insert [okay] at (i) of [evaluation v] //tells how the score is
 
else
 
 
if <(item (i) of [scores v]) < (10)> then
 
if <(item (i) of [scores v]) < (10)> then
insert [good] at (i) of [evaluation v]
+
    say [Well done.] for (1) secs
else
+
    stop [this script v]
insert [great!] at (i) of [evaluation v]
 
 
end
 
end
end
+
say [Great!] for (1) secs
change [i v] by (1)
 
 
</scratchblocks>
 
</scratchblocks>
  
*Comparing different [[variable]]s (e.g. comparing two characters' health in a game)
+
* Comparing different [[variable]]s
 +
 
 
<scratchblocks>
 
<scratchblocks>
if <(1 Health) < (2 Health)> then
+
if <(score 1) < (score 2)> then
say [Player 2 wins]
+
    say [Player 2 wins!]
 
else
 
else
say [Player 1 wins]
+
    say [Player 1 wins!]
 
end
 
end
 
</scratchblocks>
 
</scratchblocks>
  
*Asking for an opinion on a scale of 1 to 10
+
* Checking that a value is within a given range
 +
 
 
<scratchblocks>
 
<scratchblocks>
set [confirmed v] to [0] //stores yes or no is the answer is complete and acceptable
+
ask [Please rate my cookies from 1 to 10.] and wait
repeat until <(confirmed) = [1]>
+
repeat until <not <<(answer) < [1]> or <(answer) > [10]>>>
ask [How good are my cookies?] and wait
+
    ask [Please rate my cookies from 1 to 10.] and wait
if <<(answer) < (1)> or <(answer) > (10)>> then
 
say [The response must be from 1 through 10] for (2) secs
 
else
 
set [confirmed v] to [1]
 
end
 
 
end
 
end
 
</scratchblocks>
 
</scratchblocks>
  
==Workaround==
+
== Workaround ==
 
{{main|List of Block Workarounds}}
 
{{main|List of Block Workarounds}}
 
The block can be replicated with the following code:
 
The block can be replicated with the following code:
  
<!-- [[File:Workaround_for_the_()_is_less_than_()_block.png]] -->
+
<scratchblocks><(b) > (a)></scratchblocks>
<scratchblocks><not <<(a) > (b)> or <(a) = (b)>>></scratchblocks>
 
  
===Less than or equal to===
+
=== 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:
+
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. This can be done as follows:
<scratchblocks>
+
 
<not <(a) > (b)>>
+
<scratchblocks><not <(a) > (b)>></scratchblocks>
  
<<(a) < (b)> or <(a) = (b)>>
+
== See Also ==
</scratchblocks>
+
* [[() = () (block)]]
The first workaround is more efficient.
+
* [[() is greater than () (block)|() > ()]]
 +
* [[Numbers]]
  
==See Also==
 
*[[() = () (block)]]
 
*[[() is greater than () (block)|() > ()]]
 
*[[Numbers]]
 
 
{{Operators Blocks}}
 
{{Operators Blocks}}
 
[[Category:Operators Blocks]]
 
[[Category:Operators Blocks]]
 
[[de:() ist kleiner () (Block)]]
 
[[de:() ist kleiner () (Block)]]
 
[[ja:() < () (ブロック)]]
 
[[ja:() < () (ブロック)]]

Latest revision as of 04:21, 11 January 2020

The correct title of this article is () < () (block). The Scratch Wiki uses this different title because of technical restrictions.
() < ()
() < ()
Category Operators
Type Boolean

The () < () block is an Operators block and a Boolean block. The block reports true if the first value is less than the second value and false otherwise.

This block can compare both numbers and strings, which are ordered alphabetically. In Scratch 1.3 and previous versions, it only accepted numbers.

Example Uses

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

set [i v] to [1]
repeat until <<(i) > (length of [scores v])> or <(item (i) of [scores v]) < (score)>>
    change [i v] by (1)
end
insert (score) at (i) of [scores v]
  • Evaluating numbers or letters
if <(score) < (5)> then
    say [Poor job.] for (1) secs
    stop [this script v]
end
if <(item (i) of [scores v]) < (10)> then
    say [Well done.] for (1) secs
    stop [this script v]
end
say [Great!] for (1) secs
if <(score 1) < (score 2)> then
    say [Player 2 wins!]
else
    say [Player 1 wins!]
end
  • Checking that a value is within a given range
ask [Please rate my cookies from 1 to 10.] and wait
repeat until <not <<(answer) < [1]> or <(answer) > [10]>>>
    ask [Please rate my cookies from 1 to 10.] and wait
end

Workaround

Main article: List of Block Workarounds

The block can be replicated with the following code:

<(b) > (a)>

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. This can be done as follows:

<not <(a) > (b)>>

See Also

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