Java中有没有goto语句? [英] Is there any goto statement in Java?
本文介绍了Java中有没有goto语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用一些goto语句在C ++中编写了一个程序。现在,我需要在Java中编写相同的程序。 Java中是否有goto选项?如果是,如何实施?
I wrote a program in C++ with some goto statements. Now, I need to write the same program in Java. Is there any goto option in Java? If so, how it can be implemented? Is it same as the C++?
我的程序是:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,w,l,q,d;
clrscr();
printf("\nEnter the limit:");
scanf("%d",&k);
for(i = 13; i <= k ; i++)
{
repeat:
j = i%10;
if (j != 0)
{
if(i < 99)
{
for(w = 1; w <= 9; w++)
{
l = 11*w;
if (l == i){
i++;
goto repeat;
}
}
}
if(i > 99)
{
for(q = 1; q<=9 ; q++)
{
d = 111*q;
if (d == i){
i++;
goto repeat;
}
}
}
printf("%d,",i);
}
}
getch();
}
推荐答案
a goto
运算符。
您的代码可以改写为继续重复
,代替如果
repeat:
标签放置在for循环之前,则
Your code could be rewritten with continue repeat
in place of the goto repeat
, if the repeat:
label was placed just before the for loop.
Eg
repeat: for(i=13;i<=k;i++)
,然后
continue repeat;
而不是 goto repeat
这篇关于Java中有没有goto语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文