![]() |
School of Engineering and
Applied
Science Department of Computer Science CSci 49 -- Introduction to C Computing http://www.seas.gwu.edu/~csci49/spring06 Prof. Michael B. Feldman mfeldman@gwu.edu |
while(value < 25)
{
value = value 5;
printf ("The value is %d\n", value);
}
if (x == 1)
y = 5;
else
z = 10;
but we require
if (x == 1)
{
y = 5;
}
else
{
z = 10;
}
and will grade accordingly. This might seem like a lot of extra work, but it pays off later. To see this, consider adding the statement p = 4; to the block containing y = 5; In the first case, you'd have to remember to add braces; in the second case, the braces are already there, so just add the statement!
while (value < 25)
{
value = value 5;
printf ("The value is %d\n", value);
}
Note: the examples in the book are written like:
while (value < 25){
value = value 5;
printf ("The value is %d\n", value);
}
This is acceptable, but makes it much
more difficult to check that your left and right braces are balanced.
|
|
|
|
if
(x <
5)
{ y = 9; } else { if (x > 25) { y = 100; } else { y = 0; } } |
if
(x <
5)
{ y = 9; } else if (x > 25) { y = 100; } else { y = 0; }
|