How to get last index value of foreach loop in smarty,i m new for smarty I have used this code but its not working

{foreach from=$cityList key=myId item=i name=foo}
 {$i.location_name}{if $main_smarty.foreach.foo.last}<hr>{else}-{/if}
  {/foreach}

i want that when their is last city name after this its come horizontal line otherwise its like india-USA-Japan- but at last it come Japan-china

In .php i use

<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

query to find citylist
$main_smarty->assign('cityList',$cityList);
?>
Edit
Report