Possible statements

Feb 2, 2011 at 1:14am
So, I can use "while" and "if" statements. But I would like to know if there is such a thing as a "when" statement. So, if you choose to reply to this inquiry of mine, please apprise me as to whether "when" statements are real and if they are, show me an example in a source code. I don't want this to be to complicated. Just an example of a couple lines that would precede the statement, the statement its self, and a couple lines that would follow the statement). And if you like, would you just give me some statements that might be useful in the future?

Thanks for your help guys. Happy commenting!
Feb 2, 2011 at 1:28am
There is no such thing as a when statement but the while statements should perform the same actions with a little bit of code manipulation.

if the when statement existed it might look like this
1
2
3
4
5
//do-other-stuff
when (exit = 1)
{
//do-stuff
}

since we only have while statements then we use what we got.
1
2
3
4
5
6
while (exit !=1)
{
//do-other-stuff
}

//do-stuff 
Feb 2, 2011 at 1:40am
Thanks!
Feb 2, 2011 at 1:47am
If I might add to what amaac said: In the case you are thinking of something like
1
2
3
4
5
6
7
8
9
10
//doing stuff
when (exit == 1)
{
//do the exit stuff
}
//other stuff



//something that makes exit == 1; statements inside the when bracket execute 


You would need to do a little more work to create that scenario. The simpliest way is to test for exit == 1 after every time it might change, then execute a function if it did. This will work for most small programs, for larger programs there are multiple ways to handle this, such as registering it as an event or having a command queue.
Feb 2, 2011 at 1:51am
Or, use an exception, or a function, or a goto.
Feb 2, 2011 at 1:56am
I'm confused.

How is "when" different from "if"?
Feb 2, 2011 at 2:14am
It's like an event callback.
Topic archived. No new replies allowed.