The INC command

Started by geecee, February 26, 2009, 12:52:41 AM

Previous topic - Next topic

geecee

The following is from the Tutorials section


--------------------------------------------------------------------------------
Other Useful Commands For Beginners
--------------------------------------------------------------------------------

INC

   Inc is short for Increment and is a quick way to do addition with variables. If we wanted to add an amount to the variable 'A' we would normally use A=A+1 (or + any other value). This can be replaced with the following:

  Inc A: Rem Increments the value currently in numeric variable A by 1


How does one increment the value currently in numeric variable A by any other value?


********** EDIT **********

Did a search for inc - 33 pages - but could only find examples of incrementing the value currently in numeric variable by 1.

Thanks
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin


geecee

Thanks for your reply kevin.

Sorry! I meant when using the INC command.

Am I to understand that there is no way to increment the value currently in numeric variable A by any value other than 1 when using the INC command?

??? :(
Thanks
geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin


As outlined in the help (Math->INC), it's not supported

geecee

Thanks for your reply kevin.

So basic(ally) it's redundant.

:)
Thanks
geecee

LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

Makeii Runoru

Also keep in mind that variables in user-defined types will not work with Inc as well.

so if you have a type

type t_obj
-- var1
endtype
Dim OBJ as t_obj

and you wish to increase the variable in a loop or in your code, you cannot do:

inc OBJ.var1
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

geecee

Thanks for your reply Makeii Runoru


geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

Makeii Runoru

#7
You should try getting in the habit of creating your own libraries that are not supported by PB. IF you happen to find that there is not a function out there that can help you, simply make your own :P

maybe for your problem you could try:

function IncVal(var,value)
-- var = var + value
endfunction var

// this is a function that returns the new value.
// called by: variable = IncVal(variable,num)
// variable: the variable you wish to increase.
// num: the amount to increase it by.

In a short example, lets say we have a variable called var1. It is = 5. Now we want to increase it by 6. We call this preceeding function by saying

var1 = IncVar(var1,6)

You'll also find that when you start using your own libraries, you could easily link them to your program at the top by using a header, like

#include "MyHeader"

A header could serve as something as simple as another PB program.
This signature is boring, and could be improved. However, the user of this signature doesn't need a fancy signature because he or she doesn't really care for one.

geecee

Thanks for your reply Makeii Runoru.

Will give it a try ...... I've got a lot to learn.

geecee

LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)

kevin


although,

var1 = var1 + 6

is quicker and less typing :)

kevin

#10
  INC & DEC now support an optional amount parameter as of Playbasic V1.64I


Dim table(100)
Table(50)=5
For lp =0 to 9
 inc a
 inc b,Table(50)
 print str$(a)+"  "+str$(b)
next  

sync
waitkey



Even newer versions of PlayBASIC V1.64 support math short cut operators,  like,

++ ; Increase by 1
--  ; decrease by 1
+= ; add value to
-= ; subtract value from
*= ; mult by value
/= ; divide by value


These work on Variables, arrays, types etc


eg.

Variable ++   ;  same as Inc Variable
Variable --    ;  same as Dec Variable

Variable += 5   ;  same as Variable=Variable+5
Variable -= 5   ;  same as Variable=Variable-5
Variable *= 5   ;  same as Variable=Variable*5
Variable /= 5   ;  same as Variable=Variable/5

etc








geecee

Thanks for the information kevin.

I am using
Compiler Version: V1.63v
IDE Version:        1.1.7

I'll keep it in mind.

geecee
LANG MEY YER LUM REEK

A smile costs less than electricity and gives more light :)