Here’s a PHP example of mine. Can anyone find a shorter/easier way to do this?
<? foreach($posts as $post){?> <div class='<?=($c++%2==1)?‘odd’:NULL?>'> <?=$post?> </div> <? }?> <style> .odd{background-color:red;} </style>
Examples in other languages would be fun to see as well.
Fundamentally – no. That’s about as easy as it gets. You might rewrite it a bit shorter/cleaner, but the idea will be the same. This is how I would write it: