If you only want to show a certain number of categories, just set a variable up to count the number of categories being displayed. Then once you've reached your desired number of categories to display, stop.
Such as...
index = 0;
while ( osc_has_categories() && index < 12)
{
...
...
index++;
}
Change '12' to however many categories you wish to show.