Skip to content

While Loops

The while and do while loops are used in the same way in C/C++ as they are in C#.

Example

Here is the example SplashKit event loop from the while loop page.

#include "splashkit.h"
int main()
{
open_window("Circle Test", 400, 400);
clear_screen(color_white());
while ( !quit_requested())
{
fill_circle(random_color(), rnd(screen_width()), rnd(screen_height()), rnd(50));
refresh_screen();
process_events();
}
}

Here is the C/C++ version of the do while loop example.

#include "splashkit.h"
int main()
{
string again;
do
{
write_line("Hello");
write("Again: ");
again = read_line();
} (again == "y" || again == "Y");
}