What is BASIC? 🖥️
BASIC (Beginner's All-purpose Symbolic Instruction Code) is a programming language developed in 1964 that was created to make it easy for people to learn programming. BASIC became one of the most popular languages in the 70s and 80s due to its simplicity. And although it is old, BASIC is still used for teaching and writing simple programs. If you're new to programming, this is a great start! 🚀
How to start working with BASIC? 💻
To start working with BASIC, you need to install a development environment or an interpreter that will allow you to write and run programs. For example, you can use online editors such as repl.it, where you can write code directly in the browser. There are also programs such as QB64 and others that allow you to run old BASIC programs on modern computers.
Once you have installed the necessary software, you can start writing code and running your programs. Let's figure out how to start programming in BASIC.
Basic features BASIC 🔧
BASIC is a language that is characterized by simple syntax and allows you to quickly learn the basics of programming. Here are the main features of BASIC:
Easy to use: BASIC uses understandable English words, which makes it easier for beginners to learn the language. For example, the
PRINTcommand is used to display text on the screen, andINPUTis used to enter data.Working with numbers and strings: BASIC supports numeric variables (integers and real numbers), as well as strings that can store text.
Powerful loops and conditional operators: You can use loops to repeat actions, and conditional operators will help your program make decisions.
Support for simple mathematical operations: BASIC is ideal for calculations. It is easy to work with arithmetic in it.
Support for simple functions: BASIC allows you to create functions to perform repetitive tasks, which helps to avoid code duplication.
BASIC Syntax Basics 📚
The BASIC syntax is very simple and intuitive. Let's take a look at some basic commands and concepts:
1. Variables 📦
Variables in BASIC are used to store data. They can be numeric (for example, to store ages or amounts) or string (to store text). To create a variable, you just need to assign a value to it. In older versions of BASIC, the LET command was used, but in modern versions it can be omitted.
Example of a numeric variable:
LET age = 25Here, the variable age stores the value 25.
Example of a string variable:
LET name = "Alice"Here the variable name stores the string "Alice".
2. Commands for data output and input 📤📥
In BASIC, you can output text using the PRINT command and receive data from the user using the INPUT command.
Example of display:
PRINT "Hello, World!"This code will display "Hello, World!" on the screen.
Example of data entry:
INPUT "Enter your name: ", nameThis code will prompt the user to enter their name and save it in the variable name.
3. Conditional operators (IF... THEN) 🧐
Using conditional operators, you can check conditions and perform different actions depending on the result of the check. For example, you can check the age and display a message if the person is an adult or a child.
Example:
IF age >= 18 THEN
PRINT "You're an adult!"
ELSE
PRINT "You're still a child."
END IFThis code checks if the value of the variable age is greater than 18, and displays the corresponding message.
4. Cycles (FOR... NEXT) 🔄
Loops allow you to perform the same action multiple times. For example, you can print all numbers from 1 to 5 using the FOR... NEXT loop.
Example:
FOR i = 1 TO 5
PRINT i
NEXT iThis loop will display numbers from 1 to 5.
5. Simple functions 📐
In BASIC, you can define functions that perform a specific task. For example, you can create a function to calculate the square of a number.
Example of a function for calculating the square of a number:
FUNCTION square(x)
square = x * x
END FUNCTIONThis function takes the number x and returns its square. It is called like this:
LET result = square(5)Now the variable result will contain the value 25.
Simple projects in BASIC 💡
1. A simple calculator for adding numbers ➗
Let's create a calculator that will add two predetermined numbers. This is an example for understanding how to work with variables and data output.
LET num1 = 10
LET num2 = 5
LET result = num1 + num2
PRINT "Sum result: "; resultThis calculator simply adds two numbers and displays the result. It's very simple!
2. Calculating the area of a rectangle 📏
Now let's calculate the area of the rectangle. We will multiply the length by the width.
LET length = 8
LET width = 4
LET area = length * width
PRINT "Rectangle area: "; areaThis code will calculate the area of a rectangle with a length of 8 and a width of 4.
3. Counting the sum of numbers from 1 to 10 📊
Let's write a program that will sum all the numbers from 1 to 10 using a loop. This will help you understand how to work with loops and summation.
LET sum = 0
FOR i = 1 TO 10
sum = sum + i
NEXT i
PRINT "Sum of numbers from 1 to 10: "; sumThis code will sum all the numbers from 1 to 10 and display the result. This will help you understand how to work with loops and perform arithmetic operations.
Conclusion 🎉
BASIC is a great language for beginners that allows you to quickly learn the basics of programming. We covered the basics of BASIC, such as variables, input/output, conditional statements, and loops, and created a few simple programs to help you get started with programming. 🌟
Remember that programming is a skill that comes with practice. The more you program, the better you get! Good luck learning BASIC! 😊
