From Test-Scratch-Wiki

Revision as of 13:16, 4 June 2020 by Ahmetlii (talk | contribs) (translating...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Translate: - English - Türkçe - 中文 
() Mod ()
2.0 () Mod ().png
Category Operator
Type Reporter

() Mod () bloğu ("mod""modulo"nun kısaltmasıdır) bir Operatörler bloğu ve bir Reporter bloğudur. The block reports the remainder of the division when the first value is divided by the second. For example, when 10 is put in the first input and 3 in the second, the block will report 1; 10 divided by 3 gives a remainder of 1.

Negative numbers behave a little differently, because a remainder must always be positive. -10 mod 3 equals 2, not -1, because you have to multiply 3 by -4 to have any remainder at all.

Örnek Kullanımları

Eğer bir proje bölünebilirlik testi uyguluyorsa () Mod () bloğu bunun için kullanılabilir.

() Mod () bloğu için bazı yaygın kullanımlar:

  • İki sayının kalansız bölünebildiğini test etme:
eğer <((a) mod (b)) = [0]> ise 
  [a, b'ye bölünebilir] de
  [a, b'ye bölünemez] de
  • Bir sayının tam sayı olduğunu test etme
eğer <((a) mod (1)) = [0]> ise
   [a bir tam sayıdır] de
   [a tam sayı değildir] de
  • Checking if numbers are odd or even
if <((a) mod (2)) = [0]> then
   say [a is an even number]
if <((a) mod (1)) = [0]> then
   say [a is an odd number]
   say [a is not an integer]
  • Repeatedly iterating through a list:
when gf clicked
set [x v] to [0]
change [x v] by (1)
say (item (x) of [list v])
set [x v] to ((x) mod (length of [list v]))
  • Reusing background-sprites when scrolling
when gf clicked
set x to (((x position) + (240)) mod (480))


Main article: List of Block Workarounds

If only positive numbers are wanted, the block can be replicated with the following code (the variable remainder is the reported value):

if <(round ((a) / (b))) > ((a) / (b))> then
set [remainder v] to ((a) - ((round (((a) / (b)) - (0.5))) * (b)))
set [remainder v] to ((a) - ((round ((a) / (b))) * (b)))

Negative values are rarely used in the () Mod () block, although it is possible. The output given when a negative value is in the first insert and a positive value is in the second is the positive value, so if the negative value is wanted, you must subtract the number in the second insert from the remainder, as so:

if <(a) < (0)> then
if <(b) > (0)> then
set [remainder v] to (((a) mod (b)) - (b))
set [remainder v] to ((a) mod (b))
set [remainder v] to ((a) mod (b))

See Also

Template:Tur/Operatörler Blokları