🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

If else

posted in noaktree leaves
Published July 05, 2005
Advertisement
Adding control...

I added if( boolean expression ) { code block } else { code block } control to the language today. The 'else' statement is optional of course. Next I'll add a 'while' statement and then some sort of 'for' loop similar to the C 'for' statement. I can't think of how I would add a switch statement to this interpreted language so I'll skip over that one for now.

Scope...

With the addition of code blocks comes the addition of variable scope. I created a class to better manage variable memory. It enables variables to be declared inside of a code block such as an 'if' statement's code block. Once the program moves out of that scope the variables are destroyed. This basically allows for the below code to operate without any errors.

int x = 10;
int y = 12;

if (x < y)
{
int z = 22; // Declare integer z inside the scope of this code block.
print z;
} // z is destroyed here.

int z = 55; // z is declared again with no error.
print z;

Output: 22 55


The core component of the variable memory class is a stack of memory maps. Eventually every part of the code will be in one kind of function or another so every function will have its own memory class. A stack will be used to keep track of which one is currently active.
Previous Entry Boolean Express
Next Entry while (I was away)
0 likes 2 comments

Comments

Rob Loach
That's pretty neat, are incrementers in there?
July 06, 2005 10:54 AM
noaktree
No ++ or += yet. I may add those later.
July 06, 2005 12:27 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement