do
{
}
while (boolean-expression); //beware there is ";" in the end
There is actually another way to realize this using the first type of loop, like this:
// Expect notes from user until EOF
while (true)
{
// Expect note
string line = get_string("");
// Check for EOF
if (line == NULL)
{
break;
}
// Check if line is rest
if (is_rest(line))
{
rest_write(s, 1);
}
else
{
// Parse line into note and duration
string note = strtok(line, "@");
string fraction = strtok(NULL, "@");
// Write note to song
note_write(s, frequency(note), duration(fraction));
}
}
So we start by writing while(true), so it will always be true, and we set a "break" inside it. So as the above code, the input string will also run first at least once, then check if it's an empty string, if it is then will break out of the loop. If not then go further down. It will continue looping until the input is an empty string, then it will break out of the loop.