loop

1
2
3
4
5
6
7
8
9
10
11
12
char selection = '0';
int player_hp = 100;
int enemy_hp = 100;
for ( ; player_hp <= 0 || enemy_hp <= 0 ; ) {
cout << "[1]Attack [2]Run" << endl;
selection = _getch();
switch ( selection ) {
case '1': enemy_hp -= 50; break;
case '2': cout << "Escaped!" << endl; Menu(); break;
default: battle(); break;
}
}



for loop will execute its statement until the condition is true. but ,why this isnt printing anything?
Last edited on
for ( ; player_hp <= 0 || enemy_hp <= 0 ; )

Because your condition is never met...

Both player and enemy hp is 100, so it's never going to go in there.
Use a do{}while. That's executed at least once.
Topic archived. No new replies allowed.