0

How does the "double" return work in this task?

I dont understand how this code works bool key_check(string key); int main(int argc, string argv[]) { if (argc == 2 && key_check(argv[1])) printf("ok\n"); } bool key_check(string key) { for (int i= 0, n = strlen(key); i < n; i++) { if (!(key[i] >= '0' && key[i] <= '9')) { return false; return true; } as i understand it means: if key[i] is NOT between 0 and 0 - then rerutn false. But what return true means? for example argv[1] = "2a", strlen =n= 2 when i = 0 '2' is between '0' and '9'. - it will do nothing and go to the next iteration right? next iteration i = 1 'a' is not betwen '0' and '9', so because of "!" in the beginning of the condition it will retrun false what "return true" does then?

27th Feb 2021, 8:52 PM
Michael Townley
Michael Townley - avatar
1 Answer
+ 2
Return true should be below the for loop. You are missing two } in your code one for the if statement and one for the for loop.
27th Feb 2021, 9:04 PM
WildGeese
WildGeese - avatar