Sign in to follow this  
  • entries
    149
  • comments
    510
  • views
    94311

If else

Sign in to follow this  
noaktree

84 views

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.
Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now