+ 2
How can we use return statement in for loop in place of break?
3 ответов
+ 10
If you have a method, you can use the return statement instead of a break.
Elseover compile throw error.
If you want to return int,float,String,char,boolean just put this value right side of return statment.
Example i want to return int
return 100;
Here is syntax
In this programme i return void means nothing.
var a = 5;
function fun(){
for(var i =0;i <=10;i++)
{
if(i==a)
return;
console.log(i);
}
}
fun();
after reaching condition than compiler simply stops that exicution like break.
+ 2
Thankyou Sumit Programmer😎😎
+ 2
You cannot use return statement in place of break statement.
But inside a function, the for loop can be escaped with return statement.