I need to stop this while without a brake or a better way solve it

function validacion_contenidos(palabra)
{
    j=0;

    if(palabra.length >= 4)
    {
        //dw("palabra valida");
        while(j < palabra.length)
        {
            letra=palabra.charCodeAt(j);
            //dw(letra);
            if(letra >= 97 && letra <= 122 || letra >= 65 && letra <= 90)
            {
                val=true;
            }
            else
            {
                val=false;
                //how do I stop this while here without breake();
            }
            j++
        }
    }
    else
    {
        dw("Palabra invalida. Ingrese mas caracteres");
    }
    if(val == true)
    {
        dw("Palabra valida");
    }
    else
    {
        dw("Palabra invalida. Contiene caracteres no perminitdos");
    }
}

dw it's a function for document.write........

Thanks

Edited 3 Years Ago by Reverend Jim: Fixed formatting

MimoDsg,

Try this. I had to rearrange the code a bit but it should do what you want now:

function validacion_contenidos(palabra)
{
	if(palabra.length >= 4){
		//dw("palabra valida");
		for(var j=0; j<palabra.length; j++){
			letra = palabra.charCodeAt(j);
			//dw(letra);
			if(letra < 65 || (letra > 90 && letra < 97) || letra > 122)
			{
				dw("Palabra invalida. Contiene caracteres no perminitdos");
				//how do I stop this while here without breake();
				return;
			}
		}
		dw("Palabra valida");
	}
	else
	{
		dw("Palabra invalida. Ingrese mas caracteres");
	}
}

Airshow

This article has been dead for over six months. Start a new discussion instead.