If you're referring to:
x = 2 #OR y = 'FooBar' then, you're correct in noting that you don't need to declare them before giving them values. However, with regards to the following, the variable 'n' must have a value for the statement to execute at all: print(n if n is None else 'Bummer') Even JavaScript has gotten more strict about things. If a variable is not defined before its value is retrieved, an error/exception/whatever is raised. Note that this behaviour is only caused by not having a value for the variable when its non-existent getter function is called (after all, how can you retrieve something if it doesn't exist!?). You can assign a value such as undefined (JavaScript) or None (Python) just fine. Then things will work. QB seems rather unique in the fact that you can just use the following readily: IF n = 0 THEN PRINT n ELSE PRINT "Bummer" That is perfectly acceptable in QB, which is very strange compared to many other languages I've used to create programs.
|
| Response Title | Author and Date |
| I can think of some languages that let you use variables uninitialized | Dean Menezes on Apr 22 |
| * What does this have to do with QB64? | on Apr 22 |
| It is a response to rpgfan's post about python not allowing uninitialized variables | qbguy on Apr 22 |
| * Why would you want it to? | on Apr 22 |