Is there a "when" statement in C++? I mean, like:
Thanks in advance.Code:when(TRUE) { //do this }
Is there a "when" statement in C++? I mean, like:
Thanks in advance.Code:when(TRUE) { //do this }
Stupid things pop singers say
"I get to go to lots of overseas places, like Canada."
- Britney Spears
"I love what you've done with the place!"
-Jessica Simpson upon meeting the Secretary of Interior during tour of the White House
Yes, except it's cunningly referred to as while.
Nope, just use while loops
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
No, when I use while, it won't execute the code anytime the code is true. It only checks when its reached.Originally posted by Eibro
Yes, except it's cunningly referred to as while.
Stupid things pop singers say
"I get to go to lots of overseas places, like Canada."
- Britney Spears
"I love what you've done with the place!"
-Jessica Simpson upon meeting the Secretary of Interior during tour of the White House
>Is there a "when" statement in C++?
No, just negate the while loop:
>Yes, except it's cunningly referred to as while.Code:while ( !TRUE ) or while ( FALSE )
You're confusing while with some form of until. while continues as long as the condition is true, when or until continues as long as the condition is false.
-Prelude
My best code is written with the delete key.
I think what you are saying is that you want your program to do something whenever a condition is true ( for example x == 3 ), but otherwise just be running some other section of code normally.
While not the most efficient way, one method would be to spawn another thread which is constantly checking the condition and acting appropriately like
while(true) if(x == 3)doSomething();
But this is probably not the optimal solution to your problem, but if you describe more about what you are trying to do, then I can probably suggest a better way.
I'm making a RPG. I wantto activate (the exp needed is gonna go up every time levup() is called )whenever the exp meets a certain requirement. I don't want it to be check every so often.Code:levup(/*the exp needed to levelup*/100)
Stupid things pop singers say
"I get to go to lots of overseas places, like Canada."
- Britney Spears
"I love what you've done with the place!"
-Jessica Simpson upon meeting the Secretary of Interior during tour of the White House
>to activate (the exp needed is gonna go up every time levup() is called )whenever the exp meets a certain requirement. I don't want it to be check every so often.<
Why not just check for a level up whenever exp is added? Create a table of exp needed and cross reference this from your level up function.
Joe
Yeah, it's called an if check. Every time you give experience, you check to see if it levels them. How hard is that?
Code:You::GainExp( expValue ) { itsExp += expValue; CheckLevelUp( ); } You::CheckLevelUp( ) { if( itsExp >= someFormulae ) GainLevel( ); }
Quzah.
Hope is the first step on the road to disappointment.
its probably more efficient to read some tutorials or books on c++ rather than posting a whole thread on each thing as simple as an if statement
Using an if statement within a while loop is(in my book) considered an when statement.
Because within the while loop, things are happening. The if statement is like when this happens(if(this is true)) do this within the while loop.
or a while loop in an if .