duplicates - How to avoid while-loop code duplication? -
string s = console.readline(); while( s!= null) { // // .... s = console.readline(); }
the code above input, verify it, process , input again, obviously, s = console.readline();
code duplication.
what tricks there avoid duplication?
in python (where there no do-while
loop guaranteed @ least 1 iteration), trick use infinite loop explicit break.
while( true ) // or whatever evaluates true unconditionally { s = console.readline(); if (s == null) { break; } // }
Comments
Post a Comment