Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Variable/Function Question

Author
Message
Scrum
20
Years of Service
User Offline
Joined: 23rd Mar 2004
Location:
Posted: 23rd Mar 2004 17:02
Do variables declared/used inside of a function only apply to that function only? i.e x inside of random_function() would not effect x in another function/main loop

Also, is there any way of declaring/initializing a variable only once so that everytime the program passes x = 10 it ignores it since it only declared it once? Without using IF or DO WHILE code. i.e INIT X = 10 or something. (I'm aware of declaring it outside of a DO/LOOP but what happens if I want to do it inside of a loop?)
Peter H
20
Years of Service
User Offline
Joined: 20th Feb 2004
Location: Witness Protection Program
Posted: 23rd Mar 2004 18:06
Quote: "Do variables declared/used inside of a function only apply to that function only? i.e x inside of random_function() would not effect x in another function/main loop
"

All variables in a function are only used in that function (using the same variable in the function and in the main loop is fine) with the exception of...Arrays(automaticly global), And variables that you declare "Global".


Quote: "Also, is there any way of declaring/initializing a variable only once so that everytime the program passes x = 10 it ignores it since it only declared it once? Without using IF or DO WHILE code. i.e INIT X = 10 or something. (I'm aware of declaring it outside of a DO/LOOP but what happens if I want to do it inside of a loop?) "


Yes do this in the main loop if you only want x to =10 when it is NOT = to 10



You know, when i see an old lady slip and fall on the side walk, my first instinct is to luagh, but then i think, what if i where an ant? and she fell on me, it just doesn't seem so funny anymore.
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 23rd Mar 2004 22:11 Edited at: 23rd Mar 2004 22:12
If you need this,

If X<>10 then x=10

you can shorted that to

X=10

since this condition will always leave x equal to 10.
--
TAZ

Login to post a reply

Server time is: 2024-09-22 02:37:36
Your offset time is: 2024-09-22 02:37:36