+ 2

How can we use return statement in for loop in place of break?

15th Jun 2019, 2:19 AM
Pratibha Bhadouriya
Pratibha Bhadouriya - avatar
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.
15th Jun 2019, 3:01 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
15th Jun 2019, 3:07 AM
Pratibha Bhadouriya
Pratibha Bhadouriya - avatar
+ 2
You cannot use return statement in place of break statement. But inside a function, the for loop can be escaped with return statement.
15th Jun 2019, 3:08 AM
thiru mal
thiru mal - avatar