Posts Tagged ‘Loops’

Refactorings for Loops and Blocks overview

August 28th, 2012 Comments off

This is just a quick overview list to organize a bunch of refactorings that deal with loops and blocks. Click the refactoring name to learn more about it.

Add Block Delimiters

This refactoring embeds a single statement into curly braces.

Consolidate Using Statements

This refactoring combines several neighboring or nested using statements that cover variables of the same type into a single using statement.

Read more…

Refactorings for converting loops: ForEach to For and back

August 27th, 2012 Comments off

Let’s take a look at the two CodeRush refactorings allowing us to convert a for-loop into foreach-loop, and a foreach-loop into for-loop, and compare these two loops to see what the difference is between them and which one is preferred.

The for-loop is useful for iterating over elements and for sequential processing. It uses an iteration variable and is good when iterating over many items sequentially with a precise condition of the iteration termination. No collection of elements is required, but we can use the iteration variable to index a separate collection. In its basic form, the loop contains three sections:

Read more…

Coding Helpers – Reverse For Loop

August 9th, 2012 Comments off

When working with arrays and lists enumerating all of its items we usually create a for loop statement as follows:

CodeRush Reverse For Loop code sample

Read more…