(A) Loops: Programming For MSC Part I Part 4: Control Flow
(A) Loops: Programming For MSC Part I Part 4: Control Flow
(a) Loops
Definition
Example:
Example:
char c;
do
{
printf ("Enter operator or ’q’ to quit!\n");
c = getchar ();
handle_operator (c);
}
while (toupper (c) != ’Q’);
‘while’ vs ‘do-while’
Example:
Empty Loops
Example:
char buf[256];
char *s = read_string (buf);
while (*++s);
append (s, "42");
Ugly because:
char buf[256];
char *s;
for (s = read_string (buf); *s != ’\0’; s++)
{
}
append (s, "42");
Example:
if (x < y)
{
z = x;
}
else
{
z = y;
}
z = (x < y)? x: y;
Example: