EDIT
I'm leaving this up here, even though it makes me look stupid, because it's a subtle bug that can bite you if you're working late at night and not paying attention. Kudos to Visual Studio for having such an intelligent parser.
Basically I missed that I have nested loops, so the continue
statement is essentially worthless here because it is continuing the foreach
loop, not the for
loop.
ORIGINAL QUESTION
I'm running a search on a workbook, looking for the sheet that matches all the string search criteria. In the Visual Studio editor, the i++
is underlined as "unreachable code".
/// <summary>
/// Finds the first sheet that has cells that match all the criteria.
/// </summary>
/// <param name="wb"></param>
/// <param name="searches"></param>
/// <returns></returns>
public static ISheet FindSheet( this IWorkbook wb, params string[] searches )
{
if( null == wb || null == searches )
return null;
for( int i = 0; i < wb.NumberOfSheets; i++ )
{
var sheet = wb.GetSheetAt( i );
foreach( var search in searches )
{
var cell = sheet.FindCell( search );
if( null == cell )
continue;
}
return sheet;
}
return null;
}
I would think that the continue
statement has a clear meaning here: "If any of the search criteria return a null
cell, continue to the next iteration. Otherwise, just return the sheet found in this iteration."
CORRECTED CODE WITH NO CONTINUE STATEMENT
/// <summary>
/// Finds the first sheet that has cells that match all the criteria.
/// </summary>
/// <param name="wb"></param>
/// <param name="searches"></param>
/// <returns></returns>
public static ISheet FindSheet( this IWorkbook wb, params string[] searches )
{
if( null == wb || null == searches )
return null;
for( int i = 0; i < wb.NumberOfSheets; i++ )
{
var sheet = wb.GetSheetAt( i );
if( searches.All( s => null != sheet.FindCell( s ) ) )
return sheet;
}
return null;
}