0

Is condition is mandatory in for loop?

I mean for(i=1,0,i++) Loop will execute or not?

3rd Dec 2021, 11:33 AM
Ashutosh Modgil
Ashutosh Modgil - avatar
13 Answers
+ 2
What is an if-loop? Do you mean an if-statement? Or a for-loop? Or a while-loop? Only the tag the programming language that is relevant to your question.
3rd Dec 2021, 12:41 PM
Lisa
Lisa - avatar
+ 1
Without condition it would loop forever, so no it is not valid.
3rd Dec 2021, 11:39 AM
cadbrooke
cadbrooke - avatar
+ 1
There is no such thing like "if loop", though by syntax I can tell it is a for loop. If it is a for loop, loop may not execute as data type of i is not specified
3rd Dec 2021, 2:50 PM
Sanjyot21
Sanjyot21 - avatar
+ 1
I think 0 will not gonna happen this
3rd Dec 2021, 5:48 PM
Pranav Hirani
Pranav Hirani - avatar
+ 1
Try True in place of 0
3rd Dec 2021, 5:49 PM
Pranav Hirani
Pranav Hirani - avatar
+ 1
But itll happens in infinite loop So you have to define condition somewhere to exit the loop
3rd Dec 2021, 5:50 PM
Pranav Hirani
Pranav Hirani - avatar
0
You mean Infinte loop??
3rd Dec 2021, 11:40 AM
Ashutosh Modgil
Ashutosh Modgil - avatar
0
zemiak even if you use if(true) it will be executed only once, it won't be in loop
3rd Dec 2021, 5:04 PM
Sanjyot21
Sanjyot21 - avatar
0
No it is not. And with 0 condition will be false and you loop will not even run
4th Dec 2021, 8:52 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
First, all semicolons are mandatory. Second, technically the condition is not mandatory. Third, when using 0 the code will run but it will return nothing because it executes 0 times. Also, if you use an empty condition your loop will run forever.
4th Dec 2021, 10:56 PM
Chaos EMC2
Chaos EMC2 - avatar
0
What you can use of you want an infinite loop is 1==1 or something like that. Infinite loops are sometimes used for he's and the like, specifically for waiting for user input. Hope that helps.
5th Dec 2021, 3:33 AM
Joseph Fruin
Joseph Fruin - avatar
0
Although as some else mentioned, it might be simpler to use a while loop.
5th Dec 2021, 3:34 AM
Joseph Fruin
Joseph Fruin - avatar
0
If you don't provide a condition in your loop .... then it will turn out to be an infinite loop!!!
5th Dec 2021, 4:14 AM
Joy