What is wrong with my loop?
Posted
by
user3966541
on Stack Overflow
See other posts from Stack Overflow
or by user3966541
Published on 2014-08-22T04:05:18Z
Indexed on
2014/08/22
4:20 UTC
Read the original article
Hit count: 124
c++
I have the following loop and don't understand why it only runs once:
std::vector<sf::RectangleShape> shapes;
const int res_width = 640;
const int res_height = 480;
for (int x = 0; x < res_width / 50; x += 50)
{
for (int y = 0; y < res_height / 50; y += 50)
{
sf::RectangleShape shape(sf::Vector2f(50, 50));
shape.setPosition(x * 50, y * 50);
sf::Color color = (x % 2 == 0) ? sf::Color::Green : sf::Color::Red;
shape.setFillColor(sf::Color::Green);
shapes.push_back(shape);
}
}
© Stack Overflow or respective owner