+ 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

10th Apr 2022, 5:19 PM
David
David - avatar
5 ответов
+ 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..
10th Apr 2022, 5:21 PM
Jayakrishna 🇮🇳
+ 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
10th Apr 2022, 5:24 PM
David
David - avatar
+ 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..
10th Apr 2022, 5:31 PM
Jayakrishna 🇮🇳
+ 1
David Remember never return in else part inside loop.
10th Apr 2022, 5:49 PM
A͢J
A͢J - avatar
+ 1
Thank you A͢J
10th Apr 2022, 5:51 PM
David
David - avatar