What's the reason of using while loops upon event polls? Why I can't use an if statement instead?
Event polling w/ a while loop:
#include <SFML/Graphics.hpp>
int main()
{
sf::Window window;
window.create(sf::VideoMode(800,600),"My window");
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type==sf::Event::Closed)
{
window.close();
}
}
}
return 0;
}
Event polling w/o a while loop:
#include <SFML/Graphics.hpp>
int main()
{
sf::Window window;
window.create(sf::VideoMode(800,600),"My window");
while(window.isOpen())
{
sf::Event event;
if(window.pollEvent(event))
{
if(event.type==sf::Event::Closed)
{
window.close();
}
}
}
return 0;
}
I tested both, and I haven't encountered any complications. (Why I came up w/ this question: many of you including Laurent - the SFML creator - are using while loops for implementing the poll. Furthermore, one while loop is running, so why put another one inside?).
PS: The SFML documentation in general is good in terms of structure and easy accessibility, nevertheless I have no idea how every method behaves in detail. It seems to me that many methods are running implicitly on iterations.