Writing FreeDOS programs in C (flow control)

preview_player
Показать описание
Welcome to part 3 of my weekly video series, where I teach you how to write FreeDOS (or Linux) programs in C. In this video, we'll learn about flow control in C.
if-else, switch, and loops

This is part of the "Writing FreeDOS programs in C" series

Join us on Facebook

Follow us on Twitter

Consider supporting me on Patreon
Рекомендации по теме
Комментарии
Автор

Huge thanks for C tutorials! Hope to see more advanced things to learn.

emem
Автор

Here is a short program which illustrates the difference between "while" and "do while"



=== 2whiles.c ===
#include <stdio.h>

int main () {
int i = 5;
while (i < 5) {
printf("(inside the while loop)\nThe value of i is %d\n\n ", i);
i = i +1;
}
printf("(After the while loop)\nThe value of i is %d... That's unchanged\n\n", i);

i = 5;
do {
printf("(Inside the do while loop)\nThe value of i is %d\n\n", i);
i = i +1;
} while (i < 5);
printf("(After the do while loop)\nThe value of i is %d... Why?\n\n", i);
}


=== end-of-file ===


A "do while" loop will always execute at least once, then check to see whether it should execute again.

mattlivingston