+ 1
for loop returns immediately in its first iteration
can someone let me know how to fix my seating function. As long as there is a zero in the array, "airline" I need it to return false, so the while loop continues in the main function but my for loop in the function, seating, returns "true" immediately after its first iteration. here's the code https://code.sololearn.com/cCftD4xKPhyg
5 Antworten
+ 2
bool seating(bool array[])
{
for (int i = 0; i < 10; i++)
{
if (array[i] == 0)
{
return false;
}
}
return true;
}
//if-else: either if or else executed as alternatives..
+ 1
Jayakrishna🇮🇳 you have been such a big help. Thank you so much!
I just realized you answered this in my other question and i didnt pock up the “return true” change
+ 1
Yes.
return causes to come out of function.
if-else :=> if block executed when if condition is true, otherwise control goes to execute else block if any..
Hope it helps..
You're welcome..
+ 1
David
Remember never return in else part inside loop.
+ 1
Thank you A͢J