Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (the italics in the above code for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]
[color=blue]// your code is here[/color]
[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.
I would do something like this:
const byte activeCommand = 1;
const byte inactiveCommand = 0;
const byte activeState = LOW;
const byte inactiveState = HIGH;
const byte LEDpin[]={22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41};
...
for (int i=0; i<20;i++)
{
if(Serial.read() == activeCommand)
{
digitalWrite(LEDpin[i], activeState);
}
else
{
digitalWrite(LEDpin[i], inactiveState);
}
}
You'll note I put the pins in an array, which allows you to change things without editing 20 lines of code every time. I'll let you figure out how to handle the pinMode update.