- #1
Peter P.
- 23
- 0
i know that it is possible to have multiple conditions in a for loop. but is it separated by a comma or would it be separated by && like in an if statement?
Thanks
Thanks
The syntax for a for loop in C is:
for (initialization; condition; increment/decrement) {
// code to be executed
}
The initialization statement is used to initialize the loop control variable or counter before the loop starts. It is executed only once at the beginning of the loop.
The condition in a for loop is checked before each iteration of the loop. If the condition is true, the loop will continue to execute. If the condition is false, the loop will terminate and control will pass to the next statement after the loop.
Yes, the increment/decrement statement in a for loop can be omitted. This will create an infinite loop, as long as the condition is always true.
Yes, a for loop can be nested within another for loop. This allows for more complex looping structures and can be useful for iterating through multi-dimensional arrays or performing repetitive tasks.