If we're at level x the current level should be x. If we find an indent word there the level of the current line should be x + 1. unless that's the first indent word we found. If we find and outdent word there the level of current line should be x - 1. If we don't find an indent word there the level of the next line should be x. The first current level is NOT set by the first line encountered. The first current level is always 0. Before executing: line 1 next level should be 0 Check line 1: is should be at level 0 if it contains in keyword, change next level to 1 (else, next level stays at 0) Check line 2: it should be at level 1 if it contains in keyword, change next level to 2 Check line 3: it should be at level 2 if it contains an out keyword, chnage next level to 1