Questions tagged as 'loop'

3
answers

Is there a difference between reporting the size of the loop condition or outside it?

If I have an array or collection in a Arraylist and need to traverse its elements, I occasionally need to make use of loop repetition. Ex: for(int i = 0; i < arrayList.size(); i++){ //iteração... } or in the case of a simple...
asked by 13.09.2016 / 15:45
5
answers

What is the advantage of using recursive functions?

Recently I discovered the famous (or not so famous) Recursive Functions and I found the concept very interesting. But during my reading I had some doubts about the use of such. 1st What is the advantage of using Recursive Function ? For I...
asked by 11.01.2016 / 04:10
3
answers

When to use recursion and when to use loops?

A problem can be solved and get the same result as a loop or through Recursive calls to a function.
asked by 16.06.2014 / 19:13
1
answer

Why is the use of "break" bad?

In many places I've heard several comments about this, such as: "Professional programmer does not use break" "Code is not good when you see a break" Why is the use of break so frowned upon by most developers? Personally I do n...
asked by 29.05.2016 / 03:14
3
answers

foreach is a loop or iterator? Or could it be both?

In a video tutorial the instructor said not to fall into foolish to think that the foreach loop is one, and was vehement that he was an iterator. There are cases where we can scroll through the items in an array using foreach as a "compact fo...
asked by 05.03.2017 / 23:34
4
answers

Should you use break in for?

I have a question about the ties of repetition. I had a class where my teacher said that you should never use for if you do not run it from start to finish. I've seen many, many codes using this repeat structure containing a break in the...
asked by 24.09.2015 / 16:38
3
answers

What is the usefulness and importance of "do ... while"?

The while command is a repeating structure with a condition at the beginning of the declaration. Example:    while (condition) {         sentences to run   } Already do... while has verification at the end, ie, the repea...
asked by 06.08.2015 / 15:22
4
answers

What does the "do" function do in JavaScript?

I searched a lot and could not find the functionality of do in JavaScript. Example: function b(a, b) { do a = a[b]; while (a && 1 !== a.nodeType); return a }     
asked by 07.07.2017 / 15:42
1
answer

Good practices (Refactoring) - best way to treat one method with for inside another

Personal using good practice in Java how should I convert this method? Should I break in several methods and within each of them do the? public void salvarObjetos(Objeto objeto){ for(Objeto1 obj : container.getList()){ . ....
asked by 14.05.2015 / 16:51
1
answer

Is creating local variables all the time generating extra cost for the software?

I made a program that it writes to variables all the time, and with that I got a doubt, instantiating a variable all the time generates more cost than just assigning the value to an existing variable? Examples: Instantiating a variable all...
asked by 30.07.2017 / 14:16