for(;;)是什么意思

kuaidi.ping-jia.net  作者:佚名   更新日期:2024-07-05
c++中for(; ;)表示什么意思

for(; ;)是for循环语句。
for语句的语法规定,括号里面一定要有两个分号,分开三个句子。
第一个句子是初始化用的,如果没有初始化的必要,就视为空语句,加上分号。
第二个句子作为判断条件,如果没有判断条件,也视为空语句,后加一个分号。这种情况,会无限循环,相当于while(1)。如果for的执行部分,就是{}之间有break语句,可以退出。
第三个句子是执行部分执行完毕再执行的语句;无则视为空语句;此时不用再加分号。

扩展资料:
for循环语法
1、语句最简形式为:
for( ; ; )
2、一般形式为:
for(单次表达式;条件表达式;末尾循环体)
{
中间循环体;
}
其中,表示式皆可以省略,但分号不可省略,因为“;”可以代表一个空语句,省略了之后语句减少,即为语句格式发生变化,则编译器不能识别而无法进行编译。
for循环小括号里第一个“;”号前为一个为不参与循环的单次表达式,其可作为某一变量的初始化赋值语句, 用来给循环控制变量赋初值; 也可用来计算其它与for循环无关但先于循环部分处理的一个表达式。
参考资料来源:百度百科-for循环

i<10:
for(i=1;i<10是条件,i++是每次循环最后执行的语句,即在printf之后执行
{
printf("%d\for循环语句的使用
for(初始化;判断条件;n";i++)//循环中要执行的最后一句)
{
}

在C语言中,for语句使用最为灵活,它的一般形式为:
for(表达式1; 表达式2; 表达式3)  语句

它的执行过程如下:

  • 先求解表达式1。

  • 求解表达式2,若其值为真(非0),则执行for语句中指定的内嵌语句,然后执行下面第3)步;若其值为假(0),则结束循环,转到第5)步。

  • 求解表达式3。

  • 转回上面第2)步继续执行。

  • 循环结束,执行for语句下面的一个语句。

    程序执行过程如下图所示:



for
[

fɔ:,
弱fə
]
prep.
为,为了;因为;给;对于;至于;适合于
conj.
因为
prep.
为了,为…目的:
例句:
to
run
for
exercise
为锻炼而跑步
to
go
for
a
walk
去散步
属于…的;…用的:
例句:
equipment
for
the
education
教育设备
适合于…需要(或目的):
例句:
a
room
for
sleeping
卧室
medicine
for
the
children
适合于儿童使用的药物
为了成为;为了得到(或获得);为拯救(或保持):
例句:
to
fight
for
one's
life
为生存而斗争
to
send
for
a
doctor
去请医生
代替,取代;作为…的符号:
例句:
to
use
blankets
for
coats
用毯子代替外衣
a
substitute
for
butter
黄油代用品
代表,代理;为了…的利益:
例句:
to
act
for
another
代替别人
A
lawyer
acts
for
his
client.
律师代表他的当事人行动。
对…特别敏感,对…反应(或理解)快:
例句:
She
has
an
eye
for
beauty.
她对美有鉴赏力。
赞成…,支持…,拥护;有利于:
例句:
to
vote
for
a
levy
投票赞成征税
Are
you
against
it
or
for
it?
你对此事是反对呢还是赞成?
为了向…表示敬意:
例句:
to
give
a
banquet
for
someone
设宴招待某人
(开)往…,以…为目的地:
例句:
to
start
for
Beijing
出发到北京去
to
leave
for
home
动身回家
寻找,寻求;希望,渴望;贪求,期待:
例句:
to
look
for
a
lost
article
寻找失物
to
hunger
for
knowledge
渴求知识
专门(供)给,有特殊用途:

比如说for(i=0;i<10;i++)
i=0是给i一个初值i<10是判定条件i++是让这个循环结束的语句;
第一个为空,我们可以在之前给I一个值
第2个为空就是不判定条件;
第3个为空即没有驱使循环结束语句;
上面这个表达式完全等同与一下;
I=0
WHILE(1)
{
i++;}
即如果3个全部省略循环题永远循环下去。
朋友这样的答案满意了吗?

for
[强
fɔ:;
弱fə]
prep.为了,为…目的:to
run
for
exercise为锻炼而跑步to
go
for
a
walk去散步属于…的;…用的:equipment
for
the
education教育设备适合于…需要(或目的):a
room
for
sleeping卧室medicine
for
the
children适合于儿童使用的药物
PREP
If
something
is
for
someone,
they
are
intended
to
have
it
or
benefit
from
it.
为例:Isn't
that
enough
for
you?那对你来说不够吗?例:...a
table
for
two.…一张双人桌。例:He
wanted
all
the
running
of
the
business
for
himself.他想要自己管理整个企业。
2.
PREP
If
you
work
or
do
a
job
for
someone,
you
are
employed
by
them.
为…
(工作)例:I
knew
he
worked
for
a
security
firm.我知道他为一家保安公司工作。例:Have
you
had
any
experience
writing
for
radio?你有为电台撰稿的经验吗?
3.
PREP
If
you
speak
or
act
for
a
particular
group
or
organization,
you
represent
them.
代表
(某团体或机构)例:She
appears
nightly
on
the
television
news,
speaking
for
the
State
Department.她每晚出现在电视新闻上,代表国务院发言。
4.
PREP
If
someone
does
something
for
you,
they
do
it
so
that
you
do
not
have
to
do
it.
替…
(做事)例:If
your
pharmacy
doesn't
stock
the
product
you
want,
have
them
order
it
for
you.如果药房没有你所要的产品,让他们替你订货。例:I
hold
a
door
open
for
an
old
person.我替一位老人把门开开。
5.
PREP
If
you
feel
a
particular
emotion
for
someone,
you
feel
it
on
their
behalf.
替…
(感到)
[adj/n
PREP]例:This
is
the
best
thing
you've
ever
done

I
am
so
happy
for
you!这是你做过的最好的事–我真为你高兴!
6.
PREP
If
you
feel
a
particular
emotion
for
someone
or
something,
they
are
the
object
of
that
emotion,
and
you
feel
it
when
you
think
about
them.
对…
(常怀有某种感情)
[adj/n
PREP]例:John,
I'm
sorry
for
Steve,
but
I
think
you've
made
the
right
decisions.约翰,我为史蒂夫感到难过,但我想你作出了正确的决定。
7.
PREP
You
use
for
after
words
such
as
"time,"
"space,"
"money,"
or
"energy"
when
you
say
how
much
there
is
or
whether
there
is
enough
of
it
in
order
to
be
able
to
do
or
use
a
particular
thing.
供…使用例:Many
new
trains
have
space
for
wheelchair
users.许多新火车都为坐轮椅者留有空间。例:...a
huge
room
with
plenty
of
room
for
books.…可存放大量书籍的一间大屋子。
8.
PREP
You
use
for
when
you
make
a
statement
about
something
in
order
to
say
how
it
affects
or
relates
to
someone,
or
what
their
attitude
to
it
is.
对…来说例:What
matters
for
most
scientists
is
money
and
facilities.对大多数科学家来说,重要的是经费和设备。例:For
her,
books
were
as
necessary
to
life
as
bread.对她来说,书就像面包一样是生活的必需。
9.
PREP
After
some
adjective,
noun,
and
verb
phrases,
you
use
for
to
introduce
the
subject
of
the
action
indicated
by
the
following
infinitive
verb.
用于某些形容词、名词或动词词组之后,引出动词不定式的执行主语
[PREP
n
to-inf]例:It
might
be
possible
for
a
single
woman
to
be
accepted
as
a
foster
parent.有可能接受单身女子做养母。例:I
had
made
arrangements
for
my
affairs
to
be
dealt
with
by
one
of
my
children.我安排了自己的一个孩子处理我的事务。
10.
PREP
If
you
say
that
something
is
not
for
you,
you
mean
that
you
do
not
enjoy
it
or
that
it
is
not
suitable
for
you.
不被…喜欢;
不适合
[非正式]
[with
neg]例:Wendy
decided
the
sport
was
not
for
her.温迪认定这项运动不适合她。
11.
PREP
If
it
is
for
you
to
do
something,
it
is
your
responsibility
or
right
to
do
it.
由…
(负责)
[PREP
n
to-inf]例:I
wish
you
would
come
back
to
Washington
with
us,
but
that's
for
you
to
decide.我希望你和我们一起回华盛顿,但由你自己决定。
12.
PREP
For
is
the
preposition
that
is
used
after
some
nouns,
adjectives,
or
verbs
in
order
to
introduce
more
information
or
to
indicate
what
a
quality,
thing,
or
action
relates
to.
用于某些名词、形容词或动词之后,引出更多信息或指出相关的性质、事物、行为等例:Reduced-calorie
cheese
is
a
great
substitute
for
cream
cheese.低卡路里干酪是奶油干酪的极好替代品。例:Parking
lot
owners
should
be
legally
responsible
for
protecting
vehicles.停车场场主应该依法负责保护车辆。
13.
PREP
If
a
word
or
expression
has
the
same
meaning
as
another
word
or
expression,
you
can
say
that
the
first
one
is
another
word
or
expression
for
the
second
one.
(意思)
相当于例:The
technical
term
for
sunburn
is
erythema.晒斑的专业术语是红斑病。
14.
PREP
To
be
named
for
someone
means
to
be
given
the
same
name
as
them.
以…
(命名)
[美国英语]例:The
Brady
Bill
is
named
for
former
White
House
Press
Secretary
James
Brady.布雷迪法案是以前白宫新闻秘书詹姆斯·布雷迪命名的。
15.
PREP
You
use
for
in
a
piece
of
writing
when
you
mention
information
which
will
be
found
somewhere
else.
至于…
(用于指可以在文中其它地方找到的信息)例:For
further
information
on
the
life
of
William
James
Sidis,
see
Amy
Wallace,
"The
Prodigy."要了解更多关于威廉·詹姆斯·西迪斯的生平,参阅艾米·华莱士的《神童》。
16.
PREP
For
is
used
in
conditional
sentences,
in
expressions
such
as
"if
not
for"
and
"were
it
not
for,"
to
introduce
the
only
thing
which
prevents
the
main
part
of
the
sentence
from
being
true.
要不是例:
for

[fɔː;
fə]

[fɚ]
prep.
为,为了;因为;给;对于;至于;适合于conj.
因为
If
not
for
John,
Brian
wouldn't
have
learned
the
truth.要不是约翰,布莱恩不会了解真相。例:The
earth
would
be
a
frozen
ball
if
it
were
not
for
the
radiant
heat
of
the
sun.要是没有太阳的辐射热,地球将会是一个冰冻的球体。

for(;;)和while(1)完全等效
#include<stdio.h>
int main () {
int sum=0,i=1;
while(1) //这里也可以改成"for(;;)"
{
sum+=i;
i++;
if(i>10) break;
}
printf("%d",sum);
}
结果都是一样的

  • c++的 for (; ;)是什么意思啊,好像还有其他几种特殊一点的情况分别是什...
    答:for (; ;)就是无限循环。
  • 单片机for(;;)什么意思
    答:死循环,一般用于等待中断。for语句的一般形式如下:for(表达式1; 表达式2; 表达式3)(需要执行的语句);其执行过程是:表达式1首先执行且只执行一次;然后执行表达式2,通常都是一个用于判定条件的表达式,如果表达式2条件成立,就执行(需要执行的语句);然后再执行表达式3;再判断表达式2,再执行表达式3.....
  • for(;;)是什么意思?无限循环吗?
    答:对,无条件循环,循环体内需要有跳转或退出循环语句,否则会死循环。可以用于等待输入等情况。
  • c语言中 for(;;)是 什么意思?
    答:就是无限循环,没有循环变量。循环体内应有别的控制条件跳出循环,否则是死循环。
  • 单片机c语言中,for(;;)是什么意思
    答:for后面的括号内(1;2;3)1一般是做赋值、2是做判断是否满足条件、做数据加或减。若括号内(;;)条件为空就是在执行for(;;){ }时它会在{ }中作死循环。while(1){ } 参考资料:http://baike.baidu.com/view/124948.htm?fr=ala0_1 ...
  • C语言中for循环后面加;什么意思?
    答:这个for循环的语句是一个空语句,就是这个for循环将永远执行那个空语句,而不会执行后面那个printf
  • java中for(;;)是什么意思?
    答:死循环,一般java并发源码里面很多类似写法,等效于while(true);在C语言中for(;;)性能更好,编译后语言中指令较少,也能够节省内存,没有判断跳转,是比while(true)更好的无限循环;估计很多源码大神都是C语言转过来的,在Java中无性能差别。
  • C语言中 For语句后面的括号里有两个分号是什么意思啊?
    答:里面的两个分号切割开了三条语句,for(;;)是一个死循环,相当于while(1),这里一直在判断menu()函数的返回值,匹配相应的值执行相应的函数,一直在循环
  • C语言中 for(;;)指什么意思?
    答:就是没有任何条件的无限循环,和while(1)循环是一样的,就是一个无限循环的常用写法。
  • c语言中for(;;)是啥意思
    答:c语言中for(;;){} 是一个典型的循环结构。include <stdio.h> main( ){ for(int i = 0; i < 5; i++){ printf("%d\t",i);} printf("\n");} 这个程序可以输出0 1 2 3 4这5个数