That looks so complicated that is could hide any number of mistakes. The second attempt with i++; is so much simpler and more elegantsai rama krishna wrote:. . . I wrote my code as below . . .
sai rama krishna wrote:so pretty much when i think of using continue i can instead use else almost automatically right
any case where continue has to be used but not else?
Not automatically. But in this case you are using continue instead of else, as I showed you.sai rama krishna wrote:. . . when i think of using continue i can instead use else almost automatically right
There is no circumstance where continue is actually necessary, and break; is only necessary inside a switch block.any case where continue has to be used but not else?
Campbell Ritchie wrote:
Use else instead of continue
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Because in one circumstance SRK is adding the numbers, and in the other circumstance he is incrementing the loop variable. That is an if‑else to me.Piet Souris wrote:. . . Why? . . . .
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
No. Don't go changing the state of the parameter.sai rama krishna wrote:you mean like below . . .
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Anna,
welcome to the Ranch and enjoy the stay!
No, but I did, and as Piet expected, it failed.. . . Did you try your code on the array { 13, 13, 1}?
No, but I did, and as Piet expected, it failed.. . . Did you try your code on the array { 13, 13, 1}?
Piet Souris wrote:You can avoid jumps by introducing a boolean 'found13', that is set as soon as a 13 is found. The loop becomes something like:
There are three kinds of actuaries: those who can count, and those who can't.
Carey Brown wrote:One thing I find interesting in all of these challenges is the number of iterations it takes in modifying the code to get it right. Often a modification breaks something that works the time before. It seems that the turn around time to detect a broken case and to try and fix it is exceedingly long and is involving too much trial and error. By the time you've gone through the cycle N times you could have written a test framework to facilitate your debugging.
Junilu Lacar wrote:The tests are already provided so I'm not sure why you'd need to write your own framework.
Junilu Lacar wrote:I think the example walkthroughs I gave show that
1. You don't need System.out.println statements to debug
2. You don['t need a debugger to step through the code
The alternative approach can eliminate the need for the above:
1. Step the solution in one small piece at a time
2. Use one or a few similar failing tests to focus on the small piece you're stepping in
3. Run the tests frequently to verify your understanding of why the code is passing or failing
Poop goes in a willow feeder. Wipe with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
|