- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi,
I have a very basic question related to the SELECT CASE construct.
The documentation tells that is is possible to branch to the END SELECT statement only from within the SELECT CASE construct but it does not mention how to do that. My problem, is that I would like to be able to exit a CASE block before the end of the block. Is there something I missed?
Best regards,
Phil.
- Marcas:
- Intel® Fortran Compiler
Link copiado
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I do not think I have ever used it, but the EXIT statement comes to mind, in particular:
myselect: select case ( myvar )
case( 1 )
exit myselect
end select myselect
I would use the naming to make sure it exits the select construct.
Regards,
Arjen
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi Arjen,
Thanks for the suggestion, but the exit statement can only be used in a DO construct, using it into a CASE block generates a compiler error.
error #6604: The CYCLE or EXIT statement must belong to a particular DO construct, and they do not.
Best regards,
Phil.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Using EXIT in a SELECT construct is a F2008 feature we don't support yet.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi Steve,
Thanks for the reply, however what about the documentation telling that is possible to branch to the END SELECT statement from within the SELECT CASE construct? Is it also part of the F2008 feature which is not supported in the current version of the compiler?
Best regards,
Phil.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
A GOTO statement can solve many problems and make the code more readable (both in fortran and C++)
Best regards
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Hi Luigi,
If possible I would like to avoid the need to use a goto statement. I have finally managed the things differently but I am currious to know if the documentation is correct or not with respect to the implementation of the Fortran standards in my current release (IVF 14.0.0.103).
Best regards,
Phil.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
I'm looking at the current documentation and the only statement I see on this is " Branching to the END SELECT statement is allowed only from within the CASE construct." This typically would be done with a GOTO (though other branch constructs could be used). What does the text you're looking at say?
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Yes Steve, That's exactly the statement I was refering to. I was wondering how branching could be done (which set of instructions to use). I was expecting a more elegant way than a single GOTO. What type of "other branch construct" do you have in mind?
Best regards,
Phil.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Arithmetic IF, ERR=, assigned GOTO, ... Compared to these, a regular GOTO is elegant. Nothing wrong with a GOTO if used properly, but eventually you'll be able to avoid it here.
I suppose an alternative is to use IF-THEN to block out the rest of the statements in the CASE block.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
You are right, a regular GOTO is always more elegant than the other possibilities. I have finally used a IF...THEN...ELSE construct. However having the possibility to use an EXIT statement would be more interesting especially when one of the two branches of the IF...THEN...ELSE block is particularly big. I hope that this will be implemented soon.
Best regards,
Phil.
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
netphilou31 wrote:
You are right, a regular GOTO is always more elegant than the other possibilities. I have finally used a IF...THEN...ELSE construct. However having the possibility to use an EXIT statement would be more interesting especially when one of the two branches of the IF...THEN...ELSE block is particularly big. I hope that this will be implemented soon.
Best regards,
Phil.
With update 1 to 16.0 beta, one should be able to use EXIT with BLOCK construct and this can be another option:
blk: block slc: select case ( foo ) case ( FOO_1 ) slc .. exit blk case ( FOO_2 ) slc .. case default slc end select slc end block blk
- Marcar como novo
- Marcador
- Subscrever
- Silenciar
- Subscrever fonte RSS
- Destacar
- Imprimir
- Denunciar conteúdo inapropriado
Great !

- Subscrever fonte RSS
- Marcar tópico como novo
- Marcar tópico como lido
- Flutuar este Tópico para o utilizador atual
- Marcador
- Subscrever
- Página amigável para impressora