If and foreach in drupal templates

Examples of using if and foreach in drupal or general php templates:

<?php if($test == 1): ?>
<div>do something</div>
<?php endif; ?>
 
<?php if($test == 1): ?>
<div>do something</div>
<?php else: ?>
<div>do something else</div>
<?php endif; ?>
 
<?php foreach($items as $item): ?>
<?php echo $item->getTitle(); ?>
<?php endforeach; ?>