Sheerpower Logo
N.1  Working with Variables, Conditionals, and Loops

Lesson 1: Introduction to Sheerpower

Welcome to your first Sheerpower programming lesson! Sheerpower is a fast and easy-to-use language, ideal for beginners who want to learn programming quickly. In this lesson, we'll cover the basics of Sheerpower by walking you through some simple examples. You'll write and run code snippets to see how Sheerpower works.

print "Hello, World!"

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. You should see the message "Hello, World!" printed below.

Working with Variables

In programming, variables are used to store data that you can use and manipulate in your code. Sheerpower makes it easy to work with variables. Let's create a program that uses variables to store and display a message.

print "Hello, World!" message$ = "Welcome to Sheerpower!" print message$

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. This program creates a variable called message$ to store a string (text), and then it prints that string.

Simple Addition

Sheerpower can also handle numbers and perform arithmetic operations. Let's start with a simple program that adds two numbers together.

print "Hello, World!" message$ = "Welcome to Sheerpower!" print message$ num1 = 8 num2 = 12 sum = num1 + num2 print "The sum of "; num1; " and "; num2; " is "; sum

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. The program adds the two numbers and prints the result.

Subtraction and Multiplication

Now, let's try subtracting and multiplying numbers. You can modify the code to see how it works.

print "Hello, World!" message$ = "Welcome to Sheerpower!" print message$ num1 = 8 num2 = 12 sum = num1 + num2 print "The sum of "; num1; " and "; num2; " is "; sum num1 = 15 num2 = 4 difference = num1 - num2 product = num1 * num2 print "The difference between "; num1; " and "; num2; " is "; difference print "The product of "; num1; " and "; num2; " is "; product

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. This program calculates the difference and product of two numbers and prints the results.

Using Loops to Repeat Actions

Loops allow you to repeat a block of code multiple times. This is useful for tasks like counting or repeating a calculation. Let's create a program that adds up all the numbers from 1 to 5.

print "Hello, World!" message$ = "Welcome to Sheerpower!" print message$ num1 = 8 num2 = 12 sum = num1 + num2 print "The sum of "; num1; " and "; num2; " is "; sum num1 = 15 num2 = 4 difference = num1 - num2 product = num1 * num2 print "The difference between "; num1; " and "; num2; " is "; difference print "The product of "; num1; " and "; num2; " is "; product sum = 0 for i = 1 to 5 sum = sum + i next i print "The sum of numbers from 1 to 5 is "; sum

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. This loop runs from 1 to 5, adding each number to the sum. The final result is the sum of all numbers from 1 to 5.

Conditional Statements

Conditional statements allow your program to make decisions based on certain conditions. Let's create a program that checks if a number is even or odd.

print "Hello, World!" message$ = "Welcome to Sheerpower!" print message$ num1 = 8 num2 = 12 sum = num1 + num2 print "The sum of "; num1; " and "; num2; " is "; sum num1 = 15 num2 = 4 difference = num1 - num2 product = num1 * num2 print "The difference between "; num1; " and "; num2; " is "; difference print "The product of "; num1; " and "; num2; " is "; product sum = 0 for i = 1 to 5 sum = sum + i next i print "The sum of numbers from 1 to 5 is "; sum num = 7 if mod(num,2)= 0 then print "The number "; num; " is even." else print "The number "; num; " is odd." end if

Instructions: Click the COPY button above to paste the code into the text area, and then click RUN to execute the code. The program checks if the number is divisible by 2 (even) or not (odd) and prints a message accordingly.

Conclusion

Congratulations! You've completed your first Sheerpower lesson. You've learned how to use variables, perform basic arithmetic, create loops, and make decisions with conditional statements. These are the building blocks of programming. Keep practicing, and soon you'll be able to create more complex programs!

Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.
Wide screen