My question is whats return value in for example 1st, 2nd, 3rd loop (for index = 0). And why is there return 1 and 0. Am I thinking right that when index value is bigger than 4 then return 0 = break?
1st m4.number = 1; (index = 0 )
2nd m4.number = 2; ( index = 1)
3rd m4.number = 3; (index = 2)
Sorry for little chaos in mine question, but I'm a bit confused with this return 1 and 0 values.
This code snippet on its own does not really make that much sense, no matter what you set variable "m4" to it goes out of scope at line 7.
A class of Mix4 is created and a public member is set to some number. Either way this method will return the actual integer 1 or 0.
When you reach the return method the code will stop at that point, and return back to the code that invoked it (called it).
Sooo...I didnt know what return 1 and return 0 do here. I say what Ive came to and please correct me if I'm wrong.
In this case 'return 1' allows method maybeNew to run untill index is less than 5. Now 'return 0' : when index is equal or greater than 5, then'IF' loop no longer exist for main 'WHILE' loop and this is bassically amount = amount. (Because e.g. in m4a.maybeNew(5) index is equal 5 and maybeNew() returns 0).
Please don't hi‑jack threads by asking questions unrelated to the original subject. Fortunately I can split you off into a new topic. I don't have the time to go through Mix4 at the moment, but I would warn you it is more complicated than it looks at first sight.
'return 1' allows method maybeNew to run untill index is less than 5
The execution of the return 1 statement is done when the value of index is less than 5.
I'm not sure what is meant by "until". There is only one if statement in the maybeNew method that controls what is returned: either a 0 or a 1
then'IF' loop no longer exist
Some confusion there. An if statement is not a loop.
Sorry and thank you for splitting topics Campbell Richie.
Why is these lines in exercise, are they for misdirection ?
Can you ask the authors or your instructor that question?
Is it possible that the posted code is different from what is in the book?
Why do that in 2 lines? Why not:
Also this line has an undefined variable: ilosc
Excuse me, I can't edit my post. Variable 'ilosc' should be called 'amount'. That is the same word in two different languages.
jack exovery wrote:So now the Question is, Why is these lines in exercise, are they for misdirection ?
If you ever go for the OCAJP, be prepared that many questions are trick questions, and many try to lay smoke curtains (like this one).