For Loop question

It has been awhile since I have used javascript - this is a basic question.
I have a basic For Loop. Is there a way that if a certain condition is met it does not effect the counter? So if the conditions are met the counter i is not added to? If anyone can set me straight I really appreciate it - here is my try but it is obviously not working.

	for (var i = 0; i < entries.length; i++) {



		


		var playerUrl = entries[i].media$group.media$content[0].url;
if (title == 'something') {
i=i-1
}
else 
{do more stuff}
{

If the condition is dependent upon the counter’s value, then the loop won’t end unless you abort it in the else clause, but this is not good practice.
What do you want to achieve?

I don’t think the condition is dependent on the counter’s value (unless I am doing something I don’t realize.)
I am just trying to run a loop and get 5 items from an RSS feed (in this case youtube videos). If the title of the item is the one I have specified I would ike to do nothing and not have the counter added to.

So in essence
var title = my_data_feed_title

for (var i = 0; i < 5; i++) {
if (title=“unwanted”) {
DO NOTHING AND DON"T CHANGE VALUE OF i ON NEXT ITERATION
}
else
{
DO SOMETHING AND INCREMENT i BY 1 as normal)
}

That doesn’t make it any clearer for me.
Presumably the counter is needed to iterate through all the items of an array, and you can’t interfere with that unless it’s to abort the loop, which isn’t best practice.
That said, there’s nothing to stop you maintaining an additional counter that increments conditionally.

Ok, so I guess I can’t tweak the value of “i” within the loop. I guess I will need to approach this totally differently. Thanks.

The problem with changing the i variable, is that it is used to step through each of the rss entries.

If you see something you don’t like, such as “unwanted” and you do something to i so that the next time through the loop it hasn’t changed, then that same i value will be used to retrieve the same “unwanted” item that you didn’t like last time, and you have an endless loop.

A solution is to use two index values, where one is for the loop, and the other is for the item that you like.


var i, itemIndex;
for (i = 0, itemIndex = 0; i < something.length; i += 1) {
    title = ...
    if (title === 'unwanted') {
        continue; // loop around for the next title
    }
    itemIndex += 1;
    // do stuff with title and itemIndex
}

Or, instead of using itemIndex, you could do without an index at all by pushing the titles that you like on to the end of the array


var i;
for (i = 0; i < something.length; i += 1) {
    title = ...
    if (title === 'unwanted') {
        continue; // loop around for the next title
    }
    container.push(title);
}