Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. The Mod Operator

The Mod Operator

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 728 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

    Suppose we have 10 students, and we need to arrange them into a few rows. Each row can have 4 students at most.

    Here is what we will do:

    1. We assign 4 students to the first row, and then we have 6 students remaining.
    2. We assign another 4 students to the second row, and now we have 2 students left.
    3. The third row would only have the 2 remaining students

     
     

    The Mod Operator

    We can do the same calculation quickly using the “mod” operator.

    r5.gif

     

    It takes 2 input numbers A and B, and tells us what’s the remainder if we keep subtracting B from A.

    If A is exactly a multiple of B, then the mod operator would return 0:

    r6.gif

     
     

    Example - Odd or Even Number

    Suppose we need to know if a number is an “even” number or an “odd” number. We can calculate the mod of that number and 2. If the result is 0 (like “8 mod 2”), then the input is an even number; otherwise, the result has to be 1 (like “7 mod 2”), and that input number is an odd number:

    r7.gif

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode