- 1
Will the for loop execute without initialization? Explain with examples.
3 Respostas
+ 3
With "initalization" do you mean keeping the whole part in the parentheses empty:
for (;;) {...}
Or just the first statement:
for (; i < 10; i++) {...}
?
Anyways both would be valid to use, but...
In the first example you would create an infinite loop, but you can fix this with a break statement.
In the second example you still need to define variable i before the loop execution, for example:
int i = 0;
for (; i < 10; i++) {...}
Otherwise an error will happen.
+ 4
Please rather specify a relevant language name in tags above than writing 'please answer' ☝
You joined multiple courses, how to know which language you mean?
0
My question is for javascript language