antiblock
Elveron
  • Chatbox

    You don't have permission to chat.
    Load More
Karbust

Usar continue dentro de um if sem loop

4 posts in this topic

Boas

 

Estou aqui a tentar usar um if dentro de um if, tipo isto:

                else
                {
                    if (text_login_windows.Text.Length > 20)
                    {
                        int maxLength = Math.Min(text_login_windows.Text.Length, 20);
                        text_login_windows.Text = text_login_windows.Text.Substring(0, maxLength);

                        continue;
                    }

                    string password = Membership.GeneratePassword(12, 1);
                }

 

Alguém me sabe dizer como posso fazer o código continuar depois de passar dentro do if?

 

O meu objetivo é se o comprimento for maior que 20 carateres o código reduz para 20 e continua para o resto do código.

 

Tenho este erro com esse continue; aí:

No enclosing loop out of which to break or continue

 

Pelo que vi na net não é possível usar isso fora de um loop, alguém me sabe dizer outra maneira de conseguir executar isso?

 

Obrigado

Share this post


Link to post
Share on other sites
antiblock
Cyphriun

A única continuação que isso pode ter é, depois do check dos 20 chars, executar o GeneratePassword(). Para isso, remove o continue.

De resto, não estou a perceber o que queres fazer aí.

Share this post


Link to post
Share on other sites

Eu também não estou a aperceber bem o que queres fazer aí, mas se tiveres em c++ podes criar labels e saltar para outra parte do codigo.

Exemplo:

 else
                {
                    if (text_login_windows.Text.Length > 20)
                    {
                        int maxLength = Math.Min(text_login_windows.Text.Length, 20);
                        text_login_windows.Text = text_login_windows.Text.Substring(0, maxLength);

                        goto label_a;
                    }

                    string password = Membership.GeneratePassword(12, 1);
                }

label_a:
	//Do something

 

Share this post


Link to post
Share on other sites
2 horas atrás, 'PACI disse:

A única continuação que isso pode ter é, depois do check dos 20 chars, executar o GeneratePassword(). Para isso, remove o continue.

De resto, não estou a perceber o que queres fazer aí.

 

2 horas atrás, DownD disse:

Eu também não estou a aperceber bem o que queres fazer aí, mas se tiveres em c++ podes criar labels e saltar para outra parte do codigo.

Exemplo:


 else
                {
                    if (text_login_windows.Text.Length > 20)
                    {
                        int maxLength = Math.Min(text_login_windows.Text.Length, 20);
                        text_login_windows.Text = text_login_windows.Text.Substring(0, maxLength);

                        goto label_a;
                    }

                    string password = Membership.GeneratePassword(12, 1);
                }

label_a:
	//Do something

 

Eu já resolvi, realmente não precisava do continue para nada... Esqueci-me de dizer aqui que já tinha resolvido...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now