as was said by Kurdish_Assass1n, the while runs in a loop the commands following it in the script, dec %x reduces the value of %x

on @*:join:#:{
var %x = $lines(badword.txt)
; If your badword.txt has 14 lines, %x has the value "14"
while (%x) {
; /help while loops
; as long as %x has a value bigger than 0 it will perform the commands
if ($read(badword.txt,%x) isin $nick) {
kick # $nick Bad Nick!
}
dec %x
; decreases the value in %x, which started at say 14
; each loop it will decrease just like a $calc would do, then the
;if ($read(badword.txt,%x) will read line 14, then line 13 then line 12 and so on til it
;hits 0, then the loop will exit to any other scripting written in before the
;closeing } of the event

}