Lesson goal: For loops and the absolute value of numbers

Previous: Making math-facts tables | Home | Next: Adding numbers like Carl Gauss did

You can test how the absolute value of a number works using for-loops, by having a for-loop count over a range of positive and negative numbers and see how the absolute value comes out. Try out the code in the code-box. Reload this page if needed.

Now you try. Try constructing a for loop that will count through some negative numbers. Use print to display the absolute value of the numbers.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.