variables

i need help
as i am pretty new to programing
what do variables doo
and what are the purpose of them

:question:

Variables are RAM memory locations were binary values can be stored. They are used everwhere in programs. For example:

I blink an LED by this code:

main
high p0
pause 100
low p0
pause 100
goto main

but if I have a variable I can blink it a specific number of times.

temp var byte
temp = 0
main
high p0
pause 100
low p0
pause 100
temp = temp + 1
if temp < 10 then goto main
end

Now if you really don’t know what variables are for I highly suggest you get a book on a programming language(any laguage but preferably whatever language you’ll be using in the future) and read it. Just about any book on programming will have a large section on variables.

In layman’s, variables are boxes that hold things that you want your program to remember.

Remember to declare your variables at some point in your program.
How you’ll do this will depend on the programming language, but will always be one of the first things covered in their manuals.
Once declared, you can use them:

a = 2
b = a * 6

In the above case, “a” will contain a 2 and “b” will contain a 16.

New math :question: :laughing:

ok thanks and i already have
the manual but you guys helpt me out
so much that i wrote my first progam


main
  photo con p0
  hphoto con p1
loop
  if photo <100 then first
  if photo =100 then second

first 
  pos var word
setpos
   servo p4,pos,50
   servo p5,pos,-50
  goto loop
        
second
  pos1 var word
setpos1
  servo p4,pos1,50
  servo p5,pos1,50
goto loop


mainloop
  if hphoto <100 then third
  if hphoto =100 then fourth
third
  pos2 var word
setpos2
  servo p5,pos2,50
  servo p4,pos2,-50
fourth
  pos3 var word
setpos3
  servo p5,pos3,50
  servo p4,pos3,50
goto mainloop

[edit] ok iv just recently tested it
and it is not
working so can sombody
please check my program for errers

You might want to check to make sre that you’ve got this syntax right.
I’m certaintly not familiar with MBasic, but I’m thinking that you need some sort of command before “first” and “second”.
Looking at Acid’s code, I’d say that you might need to put in a “goto” there.
Then again, I may be wrong and your language’s compiler may just asume that there’s a “goto” there.