Computer Science, asked by shubham9258, 1 year ago

can we write a for loop without initialization.if you yes give example in java​

Answers

Answered by Nidhi2503
5

yes

for( ; i ≤n ; i++)

hope so it may help you

please mark me as the Brainliest answer

Answered by Rocky1951
4
Yes, A 'for' loop can be written without initialization.
A 'for' statement usually goes like: for (initialization; test-condition; update).
We can leave out any or all three of them at a time.
Therefore, for (;;) is a kind of infinite loop1 that is equivalent to 'while' (true) as there is no needed test condition.
As a matter of fact, for (int i=0; ;i++) is a kind of infinite loop1.
For ( ; *s != '\0'; s++) is a type of loop that has no initialization.
's' is the beginning point of a string and can be incremented until it meets the null character '\0' which shows the end-of-string.
It primarily means a loop through all the characters of 's'.
However, the loop can also be broken if there is a break statement in the body of the loop or there is a call to exit(), etc.
Similar questions