Function Call Returning One of Two Values?

275

Ended up getting tangled and confused again by an example given in the manual/tutorial regarding Function Calls. Here's the code:

//------------------------------------------------------------------------------------
int start()                               // Description of function start()
{                                       // Start of the function start() body
int n;                                 // Variable declaration
int T=15;                              // Predefined time
for(int i=Func_yes_ret(T);i<=10;i++)   // The use of the function in..
{                                    // Start of the cycle 'for' body
n=n+1;                              // Iterations counter
Alert ("Iteration n=",n," i=",i);   // Function call operator
}                                    // End of the cycle 'for' body
return;                                // Exit function start()
}                                       // End of the function start() body
//-------------------------------------------------------------------------------------
int Func_yes_ret (int Times_in)           // Description of the user-defined function
{                                       // Start of the user-defined function body
datetime T_cur=TimeCurrent();          // The use of the function in..
// ..the assignment operator
if(TimeHour(T_cur) > Times_in)         // The use of the function in..
//..the header of the operator 'if-else'
return(1);                          // Return value 1
return(5);                             // Return value 5
}                                       // End of the user-defined function body
//-------------------------------------------------------------------------------------

Here is the explanation given for what is happening in Expression_1 of the 'for' loop:

In the header of the operator 'for', we specify the call to the user-defined function Func_yes_ret() that can return one of two values: 1 or 5. According to this value, the amount of iterations in the cycle will change: there will be either 10 (i changes from 1 to 10) or 6 (i changes from 5 to 10) iterations.

Why would 'int i=Func_yes_ret(T)' return 'one of two values'? Shouldn't this return just the value 15? As variable 'T' is assigned with the value 15 in this previous line and 'Func_yes_ret' is calling 'T'.

I assume this has something to do with the lines:

return(1);                          // Return value 1
return(5);                             // Return value 5

But I fail to understand what 'int i=Func_yes_ret(T)' in the 'for' loop is actually doing if not calling 'T' and then assigning integer 'i' with it's value before testing the condition 'i<=10'.

I'm sure the answer to this is extremely simple for anyone familiar with function calls but I am a total beginner so this is all new information to me.. I apologise in advance for my lack of knowledge/experience around the subject.

Thanks in advance to anybody willing to provide help/assistance.

11254

koranged:

Ended up getting tangled and confused again by an example given in the manual/tutorial regarding Function Calls. Here's the code:

Here is the explanation given for what is happening in Expression_1 of the 'for' loop:

In the header of the operator 'for', we specify the call to the user-defined function Func_yes_ret() that can return one of two values: 1 or 5. According to this value, the amount of iterations in the cycle will change: there will be either 10 (i changes from 1 to 10) or 6 (i changes from 5 to 10) iterations.

Why would 'int i=Func_yes_ret(T)' return 'one of two values'? Shouldn't this return just the value 15? As variable 'T' is assigned with the value 15 in this previous line and 'Func_yes_ret' is calling 'T'.

I assume this has something to do with the lines:

But I fail to understand what 'int i=Func_yes_ret(T)' in the 'for' loop is actually doing if not calling 'T' and then assigning integer 'i' with it's value before testing the condition 'i<=10'.

I'm sure the answer to this is extremely simple for anyone familiar with function calls but I am a total beginner so this is all new information to me.. I apologise in advance for my lack of knowledge/experience around the subject.

Thanks in advance to anybody willing to provide help/assistance.

//-------------------------------------------------------------------------------------
int Func_yes_ret (int Times_in)           // Description of the user-defined function
{                                       // Start of the user-defined function body
datetime T_cur=TimeCurrent();          // The use of the function in..
// ..the assignment operator
if(TimeHour(T_cur) > Times_in)         // The use of the function in..
//..the header of the operator 'if-else'
return(1);                          // Return value 1
return(5);                             // Return value 5
}                                       // End of the user-defined function body
//-------------------------------------------------------------------------------------

... is ...

if(TimeHour(T_cur) > Times_in) { return(1); }

You missed the indentation.