What does a for loop without any curly braces around it do?
So from what I know, that during an if-statement only the first line of the code is executed. So in a for loop how does it work?
I don't really understand the concept of a loop without the braces and with the braces. I guess an explanation with a piece of code would help. This is in C by the way. Here's a code I've been looking at as a reference.
int main(int argc, char* argv[])
{
int i;
int count = 0;
for (i = 0; i < 5; i++)
count++;
printf("The value of count is: %d\n", count);
return 0;
}
In this case, I see that there is no curly braces, so I am assuming that it will just keep iterating the first statement until i < 5 and once i is not less than 5 it doesn't do anything, but when I tested the code I get that it also ends up printing the printf statement. I thought that a loop without curly braces executed only the first line of code? Or am I missing something here.